From 30706b82e62ebf8096d851fb181dd51df71ff41f Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 22 Feb 2021 08:58:40 +0100 Subject: [PATCH 1/2] Use definition of DTypeLike from Numpy And fall back to original definition with older versions of numpy --- xarray/core/npcompat.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/xarray/core/npcompat.py b/xarray/core/npcompat.py index 1018332df29..8e2157cfc2d 100644 --- a/xarray/core/npcompat.py +++ b/xarray/core/npcompat.py @@ -75,11 +75,12 @@ def moveaxis(a, source, destination): return result -# Type annotations stubs. See also / to be replaced by: -# https://github.com/numpy/numpy/issues/7370 -# https://github.com/numpy/numpy-stubs/ -DTypeLike = Union[np.dtype, str] - +# Type annotations stubs. +try: + from numpy.typing import DTypeLike +except ImportError: + # fall back for numpy < 1.20 + DTypeLike = Union[np.dtype, str] # from dask/array/utils.py def _is_nep18_active(): From 35c36b87bb6937c45c4ae6b5564973f89214d216 Mon Sep 17 00:00:00 2001 From: "Jens H. Nielsen" Date: Mon, 22 Feb 2021 09:04:37 +0100 Subject: [PATCH 2/2] fix flake8 --- xarray/core/npcompat.py | 1 + 1 file changed, 1 insertion(+) diff --git a/xarray/core/npcompat.py b/xarray/core/npcompat.py index 8e2157cfc2d..40576d1fc37 100644 --- a/xarray/core/npcompat.py +++ b/xarray/core/npcompat.py @@ -82,6 +82,7 @@ def moveaxis(a, source, destination): # fall back for numpy < 1.20 DTypeLike = Union[np.dtype, str] + # from dask/array/utils.py def _is_nep18_active(): class A: