Skip to content

numpy dtype handling in 3.14 (?) typing #3688

@ilan-gold

Description

@ilan-gold

In #3564 we are now getting failures (As of ca2d9d1) like:


src/zarr/core/dtype/npy/time.py:540: error: Returning Any from function declared to return "timedelta64[timedelta | int | None]"  [no-any-return]
src/zarr/core/dtype/npy/time.py:540: error: No overload variant of "timedelta64" matches argument types "str | int | bytes | timedelta64[timedelta | int | None] | timedelta | None", "str"  [call-overload]
src/zarr/core/dtype/npy/time.py:540: note: Possible overload variants:
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | timedelta64[timedelta | int | None] | None, /) -> timedelta64[timedelta | int | None]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls) -> timedelta64[Literal[0]]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, Literal['NAT', 'NaT', 'nat', b'NAT', b'NaT', b'nat'] | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> timedelta64[None]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, Literal[0], Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[Literal[0]]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, int | integer[Any] | numpy.bool[builtins.bool], Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[int]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta, Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> timedelta64[int]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | integer[Any] | numpy.bool[builtins.bool], Literal['W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex] = ..., /) -> timedelta64[timedelta]
src/zarr/core/dtype/npy/time.py:540: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | timedelta64[timedelta | int | None] | numpy.bool[builtins.bool] | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[timedelta | int | None]
src/zarr/core/dtype/npy/time.py:586: error: Returning Any from function declared to return "timedelta64[timedelta | int | None]"  [no-any-return]
src/zarr/core/dtype/npy/time.py:586: error: No overload variant of "timedelta64" matches argument types "Literal['NaT'] | int", "str"  [call-overload]
src/zarr/core/dtype/npy/time.py:586: note: Possible overload variants:
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | timedelta64[timedelta | int | None] | None, /) -> timedelta64[timedelta | int | None]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls) -> timedelta64[Literal[0]]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, Literal['NAT', 'NaT', 'nat', b'NAT', b'NaT', b'nat'] | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> timedelta64[None]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, Literal[0], Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[Literal[0]]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, int | integer[Any] | numpy.bool[builtins.bool], Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[int]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta, Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> timedelta64[int]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | integer[Any] | numpy.bool[builtins.bool], Literal['W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex] = ..., /) -> timedelta64[timedelta]
src/zarr/core/dtype/npy/time.py:586: note:     def [_TD64ItemT_co: timedelta | int | None] __new__(cls, timedelta | int | str | bytes | character[str | bytes] | number[Any, int | float | complex] | timedelta64[timedelta | int | None] | numpy.bool[builtins.bool] | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> timedelta64[timedelta | int | None]
src/zarr/core/dtype/npy/time.py:813: error: Returning Any from function declared to return "datetime64[date | int | None]"  [no-any-return]
src/zarr/core/dtype/npy/time.py:813: error: No overload variant of "datetime64" matches argument types "str | int | bytes | datetime64[date | int | None] | datetime | None", "str"  [call-overload]
src/zarr/core/dtype/npy/time.py:813: note: Possible overload variants:
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, datetime64[date | int | None], /) -> datetime64[date | int | None]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None, _AnyDT64Arg: (datetime, date, None)] __new__(cls, _AnyDT64Arg, /) -> datetime64[_AnyDT64Arg]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, Literal['NAT', 'NaT', 'nat', b'NAT', b'NaT', b'nat'] | None = ..., Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> datetime64[None]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, Literal['NOW', 'now', b'NOW', b'now'], Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex] = ..., /) -> datetime64[datetime]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, Literal['TODAY', 'today', b'TODAY', b'today'] | _HasDateAttributes, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'], SupportsIndex] = ..., /) -> datetime64[date]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, int | bytes | str | date, Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex], /) -> datetime64[int]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, int | bytes | str | date, Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'] | tuple[Literal['h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us'], SupportsIndex], /) -> datetime64[datetime]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, int | bytes | str | date, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D'], SupportsIndex], /) -> datetime64[date]
src/zarr/core/dtype/npy/time.py:813: note:     def [_DT64ItemT_co: date | int | None] __new__(cls, bytes | str | date | None, Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'] | tuple[Literal['Y', 'M', b'Y', b'M', 'W', 'D', b'W', b'D', 'h', 'm', 's', 'ms', 'us', 'μs', b'h', b'm', b's', b'ms', b'us', 'ns', 'ps', 'fs', 'as', b'ns', b'ps', b'fs', b'as'], SupportsIndex] = ..., /) -> datetime64[date | int | None]
src/zarr/core/dtype/npy/string.py:175: error: Incompatible return value type (got "dtype[str_]", expected "StrDType[int]")  [return-value]
src/zarr/core/dtype/npy/int.py:603: error: Incompatible return value type (got "dtype[signedinteger[_16Bit]]", expected "Int16DType")  [return-value]
src/zarr/core/dtype/npy/int.py:765: error: Incompatible return value type (got "dtype[unsignedinteger[_16Bit]]", expected "UInt16DType")  [return-value]
src/zarr/core/dtype/npy/int.py:948: error: Incompatible return value type (got "dtype[signedinteger[_32Bit]]", expected "Int32DType")  [return-value]
src/zarr/core/dtype/npy/int.py:1111: error: Incompatible return value type (got "dtype[unsignedinteger[_32Bit]]", expected "UInt32DType")  [return-value]
src/zarr/core/dtype/npy/int.py:1269: error: Incompatible return value type (got "dtype[signedinteger[_64Bit]]", expected "Int64DType")  [return-value]
src/zarr/core/dtype/npy/int.py:1400: error: Incompatible return value type (got "dtype[unsignedinteger[_64Bit]]", expected "UInt64DType")  [return-value]
src/zarr/core/dtype/__init__.py:272: error: Unused "type: ignore" comment  [unused-ignore]

some of which make some sense but are out of my domain of expertise (datetime handling) and some of which strike me as potential numpy bugs (why are dtype[unsignedinteger[_64Bit]] and UInt64DType not the same thing???)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions