Skip to content

Commit

Permalink
use numpys SupportsDtype (pydata#7521)
Browse files Browse the repository at this point in the history
  • Loading branch information
headtr1ck authored Feb 28, 2023
1 parent 4194920 commit 6531b57
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions xarray/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
Any,
Callable,
Literal,
Protocol,
SupportsIndex,
TypeVar,
Union,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 6531b57

Please sign in to comment.