From b95a91bfefedfee58886a6a093712740fb36e2a2 Mon Sep 17 00:00:00 2001 From: strnh Date: Wed, 5 Mar 2025 16:14:01 +0900 Subject: [PATCH 1/5] fix: AttributeError: was removed in the NumPy 2.0 release. Use instead. --- pandas_access/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_access/__init__.py b/pandas_access/__init__.py index 9fffccb..ab2f66e 100644 --- a/pandas_access/__init__.py +++ b/pandas_access/__init__.py @@ -32,7 +32,7 @@ def _extract_dtype(data_type): # open an issue. data_type = data_type.lower() if data_type.startswith('double'): - return np.float_ + return np.float64_ elif data_type.startswith('long'): return np.int_ else: From 2ba92213f58f5742a3ff0e41fd7e86d8fcaa303b Mon Sep 17 00:00:00 2001 From: strnh Date: Wed, 5 Mar 2025 16:14:25 +0900 Subject: [PATCH 2/5] fix: AttributeError: was removed in the NumPy 2.0 release. Use instead. :take2 --- pandas_access/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_access/__init__.py b/pandas_access/__init__.py index ab2f66e..8b46d8d 100644 --- a/pandas_access/__init__.py +++ b/pandas_access/__init__.py @@ -32,7 +32,7 @@ def _extract_dtype(data_type): # open an issue. data_type = data_type.lower() if data_type.startswith('double'): - return np.float64_ + return np.float64 elif data_type.startswith('long'): return np.int_ else: From d3c4437b55def8ef71bc36832078ee3ee957e902 Mon Sep 17 00:00:00 2001 From: strnh Date: Sat, 15 Mar 2025 20:30:42 +0900 Subject: [PATCH 3/5] Numeric Column(long int) with NULL -> replace numpy.int_ to pandas Int64 --- pandas_access/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas_access/__init__.py b/pandas_access/__init__.py index 8b46d8d..78836cc 100644 --- a/pandas_access/__init__.py +++ b/pandas_access/__init__.py @@ -34,7 +34,7 @@ def _extract_dtype(data_type): if data_type.startswith('double'): return np.float64 elif data_type.startswith('long'): - return np.int_ + return 'Int64' else: return None From c5d43f26b96b6e521c7c6dd3d605ce2f6477de1e Mon Sep 17 00:00:00 2001 From: strnh Date: Sat, 15 Mar 2025 21:46:12 +0900 Subject: [PATCH 4/5] add description for Handling Nan value.. --- NaN-ja.md | 13 +++++++++++++ NaN.md | 14 ++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 NaN-ja.md create mode 100644 NaN.md diff --git a/NaN-ja.md b/NaN-ja.md new file mode 100644 index 0000000..05333f2 --- /dev/null +++ b/NaN-ja.md @@ -0,0 +1,13 @@ +## NaN 値の扱いについて + +問題:  _extract_dtype() 関数では、AccessDBの項目属性の `long` = 32bit長整数型を、 +numpyでの整数型(マシンにより32/64bit長の) `int_` すなわち Python組み込み型の `int` を +pandasが実装している配列での項目型属性パラメータ dtypes に 直接指定しています。 +しかし実際のAccessDBでは、長整数型の項目でも NULL値が許されていて、しばしばエラーになります。 + +## 回避策: 'Int64' を使う。 + +この問題を解決するためには、`np.int_` の代わりに `np.float_` 型を使うのは一つの方法です。 +しかし、整数型として扱いたい場合は不便です。 代わりに、NaN 値を扱えるようにするために、 +Pandas の `Int64` 型を使うことができます。`Int64` 型は、欠損値(NaN)をサポートする整数型です。 + diff --git a/NaN.md b/NaN.md new file mode 100644 index 0000000..b19f45d --- /dev/null +++ b/NaN.md @@ -0,0 +1,14 @@ +## Handling NaN value data types +Problem: + +The `_extract_dtype()function directly specifies Microsoft Access DB's item attribute long (..32-bit long integer type) as int_, +which corresponds to NumPy's integer type (whose bit-length varies by machine, 32/64 bits) +and the array item type parameter dtypes implemented in pandas using Python's built-in type int. +However, in actual Microsoft Access DBs, items of the long integer type can accept NULL values, often resulting in errors. + +## Solution : Use 'Int64' + +To solve this problem, one approach is to use the np.float_ type instead of np.int_. However, if you +want to maintain integer handling, this can be inconvenient. Alternatively, you could use Pandas's +Int64 type to accommodate NaN values. The "Int64" type supports missing values (NaN) for integers. + From 7c198b62e872f7a41748e232f11d12e3d202ebc0 Mon Sep 17 00:00:00 2001 From: strnh Date: Sat, 15 Mar 2025 22:07:10 +0900 Subject: [PATCH 5/5] write a test --- tests/test__extract_dtype.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/test__extract_dtype.py diff --git a/tests/test__extract_dtype.py b/tests/test__extract_dtype.py new file mode 100644 index 0000000..1fa4295 --- /dev/null +++ b/tests/test__extract_dtype.py @@ -0,0 +1,17 @@ +import unittest +import patch +import pandas as pd +import numpy as np +# target +from pandas_access import _extract_dtype + +class TestPandasAccess(unittest.TestCase): + def test_extract_dtype_double(self): + self.assertEqual(_extract_dtype('double'),np.float64) + def test_extract_dtype_long(self): + self.assertEqual(_extract_dtype('long'),'Int64') + def test_extract_dtype_unknown(self): + self.assertIsNone(_extract_dtype('unknown')) + +if __name__=='__main__': + unittest.main()