Skip to content

Commit 6531b57

Browse files
authored
use numpys SupportsDtype (#7521)
1 parent 4194920 commit 6531b57

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

xarray/core/types.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
Any,
88
Callable,
99
Literal,
10-
Protocol,
1110
SupportsIndex,
1211
TypeVar,
1312
Union,
@@ -18,6 +17,7 @@
1817
from packaging.version import Version
1918

2019
if TYPE_CHECKING:
20+
from numpy._typing import _SupportsDType
2121
from numpy.typing import ArrayLike
2222

2323
from xarray.backends.common import BackendEntrypoint
@@ -50,19 +50,12 @@
5050
_ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]]
5151
_DTypeLikeNested = Any # TODO: wait for support for recursive types
5252

53-
# once NumPy 1.21 is minimum version, use NumPys definition directly
54-
# 1.20 uses a non-generic Protocol (like we define here for simplicity)
55-
class _SupportsDType(Protocol):
56-
@property
57-
def dtype(self) -> np.dtype:
58-
...
59-
6053
# Xarray requires a Mapping[Hashable, dtype] in many places which
6154
# conflics with numpys own DTypeLike (with dtypes for fields).
6255
# https://numpy.org/devdocs/reference/typing.html#numpy.typing.DTypeLike
6356
# This is a copy of this DTypeLike that allows only non-Mapping dtypes.
6457
DTypeLikeSave = Union[
65-
np.dtype,
58+
np.dtype[Any],
6659
# default data type (float64)
6760
None,
6861
# array-scalar types and generic types
@@ -78,7 +71,7 @@ def dtype(self) -> np.dtype:
7871
# because numpy does the same?
7972
list[Any],
8073
# anything with a dtype attribute
81-
_SupportsDType,
74+
_SupportsDType[np.dtype[Any]],
8275
]
8376
try:
8477
from cftime import datetime as CFTimeDatetime

0 commit comments

Comments
 (0)