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 diff --git a/src/zarr/core/dtype/npy/int.py b/src/zarr/core/dtype/npy/int.py index 79d3ce2d47..d3423ed61a 100644 --- a/src/zarr/core/dtype/npy/int.py +++ b/src/zarr/core/dtype/npy/int.py @@ -420,6 +420,26 @@ 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`` + + 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 + 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..71257907d5 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("