From 7cc60a1f1fb1d6166f8bc6011a9b8b1e49143067 Mon Sep 17 00:00:00 2001 From: Davis Bennett Date: Wed, 18 Jun 2025 21:55:53 +0200 Subject: [PATCH 1/4] fix int32 inference on windows --- src/zarr/core/dtype/npy/int.py | 17 +++++++++++++++++ tests/test_dtype/test_npy/test_int.py | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/zarr/core/dtype/npy/int.py b/src/zarr/core/dtype/npy/int.py index 79d3ce2d47..d082f07ab7 100644 --- a/src/zarr/core/dtype/npy/int.py +++ b/src/zarr/core/dtype/npy/int.py @@ -420,6 +420,23 @@ class Int32(BaseInt[np.dtypes.Int32DType, np.int32], HasEndianness): _zarr_v3_name: ClassVar[Literal["int32"]] = "int32" _zarr_v2_names: ClassVar[tuple[Literal[">i4"], Literal["i4", " TypeGuard[np.dtypes.Int32DType]: + """ + A type guard that checks if the input is assignable to the type of ``cls.dtype_class`` + + Parameters + ---------- + dtype : TDType + The dtype to check. + + Returns + ------- + Bool + True if the dtype matches, False otherwise. + """ + return super()._check_native_dtype(dtype) or dtype == np.dtypes.Int32DType() + @classmethod def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self: if cls._check_native_dtype(dtype): diff --git a/tests/test_dtype/test_npy/test_int.py b/tests/test_dtype/test_npy/test_int.py index 5887cb0d5e..69da7bd956 100644 --- a/tests/test_dtype/test_npy/test_int.py +++ b/tests/test_dtype/test_npy/test_int.py @@ -75,7 +75,10 @@ class TestInt16(BaseTestZDType): class TestInt32(BaseTestZDType): test_cls = Int32 scalar_type = np.int32 - valid_dtype = (np.dtype(">i4"), np.dtype("i4"), np.dtype(" Date: Wed, 18 Jun 2025 21:59:24 +0200 Subject: [PATCH 2/4] docstring --- src/zarr/core/dtype/npy/int.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/zarr/core/dtype/npy/int.py b/src/zarr/core/dtype/npy/int.py index d082f07ab7..7a6ed0dddc 100644 --- a/src/zarr/core/dtype/npy/int.py +++ b/src/zarr/core/dtype/npy/int.py @@ -425,6 +425,9 @@ def _check_native_dtype(cls: type[Self], dtype: TBaseDType) -> TypeGuard[np.dtyp """ A type guard that checks if the input is assignable to the type of ``cls.dtype_class`` + This method is overridden for this particular data type because of a windows-specific issue where + np.dtype('i') is an instance of ``np.dtypes.IntDType``, not an instance of ``np.dtypes.Int32DType``. + Parameters ---------- dtype : TDType From 6032452a915502d025820123019ece7b5cc4d2d8 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Thu, 19 Jun 2025 00:17:22 +0200 Subject: [PATCH 3/4] pre-commit --- src/zarr/core/dtype/npy/int.py | 2 +- tests/test_dtype/test_npy/test_int.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/zarr/core/dtype/npy/int.py b/src/zarr/core/dtype/npy/int.py index 7a6ed0dddc..d3423ed61a 100644 --- a/src/zarr/core/dtype/npy/int.py +++ b/src/zarr/core/dtype/npy/int.py @@ -425,7 +425,7 @@ def _check_native_dtype(cls: type[Self], dtype: TBaseDType) -> TypeGuard[np.dtyp """ A type guard that checks if the input is assignable to the type of ``cls.dtype_class`` - This method is overridden for this particular data type because of a windows-specific issue where + This method is overridden for this particular data type because of a windows-specific issue where np.dtype('i') is an instance of ``np.dtypes.IntDType``, not an instance of ``np.dtypes.Int32DType``. Parameters diff --git a/tests/test_dtype/test_npy/test_int.py b/tests/test_dtype/test_npy/test_int.py index 69da7bd956..71257907d5 100644 --- a/tests/test_dtype/test_npy/test_int.py +++ b/tests/test_dtype/test_npy/test_int.py @@ -75,10 +75,10 @@ class TestInt16(BaseTestZDType): class TestInt32(BaseTestZDType): test_cls = Int32 scalar_type = np.int32 - # The behavior of some tests associated with this class variable are - # order-dependent -- np.dtype('i') correctly fails certain tests only if it's not + # The behavior of some tests associated with this class variable are + # order-dependent -- np.dtype('i') correctly fails certain tests only if it's not # in the last position of the tuple. I have no idea how this is possible! - valid_dtype = (np.dtype('i'), np.dtype(">i4"), np.dtype("i4"), np.dtype(" Date: Thu, 19 Jun 2025 00:49:24 +0200 Subject: [PATCH 4/4] changelog --- changes/3151.bugfix.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/3151.bugfix.rst diff --git a/changes/3151.bugfix.rst b/changes/3151.bugfix.rst new file mode 100644 index 0000000000..15c92dbbb5 --- /dev/null +++ b/changes/3151.bugfix.rst @@ -0,0 +1,2 @@ +Fixed an issue preventing correct parsing of NumPy ``int32`` dtypes when constructed via +``np.dtype('i')``. \ No newline at end of file