From 824d01927f487e7348274928050029aca2f1d149 Mon Sep 17 00:00:00 2001 From: Michael Niklas Date: Fri, 10 Feb 2023 21:15:12 +0100 Subject: [PATCH] use numpys SupportsDtype --- xarray/core/types.py | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/xarray/core/types.py b/xarray/core/types.py index 7149443c0c7..0f11b16b003 100644 --- a/xarray/core/types.py +++ b/xarray/core/types.py @@ -7,7 +7,6 @@ Any, Callable, Literal, - Protocol, SupportsIndex, TypeVar, Union, @@ -18,6 +17,7 @@ from packaging.version import Version if TYPE_CHECKING: + from numpy._typing import _SupportsDType from numpy.typing import ArrayLike from xarray.backends.common import BackendEntrypoint @@ -50,19 +50,12 @@ _ShapeLike = Union[SupportsIndex, Sequence[SupportsIndex]] _DTypeLikeNested = Any # TODO: wait for support for recursive types - # once NumPy 1.21 is minimum version, use NumPys definition directly - # 1.20 uses a non-generic Protocol (like we define here for simplicity) - class _SupportsDType(Protocol): - @property - def dtype(self) -> np.dtype: - ... - # Xarray requires a Mapping[Hashable, dtype] in many places which # conflics with numpys own DTypeLike (with dtypes for fields). # https://numpy.org/devdocs/reference/typing.html#numpy.typing.DTypeLike # This is a copy of this DTypeLike that allows only non-Mapping dtypes. DTypeLikeSave = Union[ - np.dtype, + np.dtype[Any], # default data type (float64) None, # array-scalar types and generic types @@ -78,7 +71,7 @@ def dtype(self) -> np.dtype: # because numpy does the same? list[Any], # anything with a dtype attribute - _SupportsDType, + _SupportsDType[np.dtype[Any]], ] try: from cftime import datetime as CFTimeDatetime