Skip to content

Commit 7cc60a1

Browse files
committed
fix int32 inference on windows
1 parent 7f4a681 commit 7cc60a1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/zarr/core/dtype/npy/int.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,23 @@ class Int32(BaseInt[np.dtypes.Int32DType, np.int32], HasEndianness):
420420
_zarr_v3_name: ClassVar[Literal["int32"]] = "int32"
421421
_zarr_v2_names: ClassVar[tuple[Literal[">i4"], Literal["<i4"]]] = (">i4", "<i4")
422422

423+
@classmethod
424+
def _check_native_dtype(cls: type[Self], dtype: TBaseDType) -> TypeGuard[np.dtypes.Int32DType]:
425+
"""
426+
A type guard that checks if the input is assignable to the type of ``cls.dtype_class``
427+
428+
Parameters
429+
----------
430+
dtype : TDType
431+
The dtype to check.
432+
433+
Returns
434+
-------
435+
Bool
436+
True if the dtype matches, False otherwise.
437+
"""
438+
return super()._check_native_dtype(dtype) or dtype == np.dtypes.Int32DType()
439+
423440
@classmethod
424441
def from_native_dtype(cls: type[Self], dtype: TBaseDType) -> Self:
425442
if cls._check_native_dtype(dtype):

tests/test_dtype/test_npy/test_int.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,10 @@ class TestInt16(BaseTestZDType):
7575
class TestInt32(BaseTestZDType):
7676
test_cls = Int32
7777
scalar_type = np.int32
78-
valid_dtype = (np.dtype(">i4"), np.dtype("<i4"))
78+
# The behavior of some tests associated with this class variable are
79+
# order-dependent -- np.dtype('i') correctly fails certain tests only if it's not
80+
# in the last position of the tuple. I have no idea how this is possible!
81+
valid_dtype = (np.dtype('i'), np.dtype(">i4"), np.dtype("<i4"))
7982
invalid_dtype = (
8083
np.dtype(np.int8),
8184
np.dtype(np.uint16),

0 commit comments

Comments
 (0)