Skip to content

Commit 042c9e5

Browse files
committed
fix: add special check for resolving int32 on windows
1 parent ea2d0bf commit 042c9e5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/zarr/core/dtype/_numpy.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,15 @@ class Int32(ZDType[np.dtypes.Int32DType, np.int32]):
429429
_zarr_v2_names: ClassVar[tuple[str, ...]] = (">i4", "<i4")
430430
endianness: Endianness | None = "little"
431431

432+
@classmethod
433+
def from_dtype(cls: type[Self], dtype: _BaseDType) -> Self:
434+
# We override the base implementation to address a windows-specific, pre-numpy 2 issue where
435+
# ``np.dtype('i')`` is an instance of ``np.dtypes.IntDType`` that acts like `int32` instead of ``np.dtype('int32')``
436+
if dtype == np.dtypes.Int32DType():
437+
return cls._from_dtype_unsafe(np.dtypes.Int32DType().newbyteorder(dtype.byteorder))
438+
else:
439+
return super().from_dtype(dtype)
440+
432441
@classmethod
433442
def _from_dtype_unsafe(cls, dtype: np.dtypes.Int32DType) -> Self:
434443
byte_order = cast("EndiannessNumpy", dtype.byteorder)

0 commit comments

Comments
 (0)