From 04239ef693d23d362e3f26b99feb8a2b4450f704 Mon Sep 17 00:00:00 2001 From: David Hoese Date: Thu, 22 Apr 2021 07:08:54 -0500 Subject: [PATCH 1/2] Fix requiring newer numpy just for typing annotations --- satpy/enhancements/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/satpy/enhancements/__init__.py b/satpy/enhancements/__init__.py index 6036aef617..cf6c5ea05a 100644 --- a/satpy/enhancements/__init__.py +++ b/satpy/enhancements/__init__.py @@ -17,7 +17,6 @@ """Enhancements.""" import numpy as np -from numpy.typing import ArrayLike import xarray as xr import dask import dask.array as da @@ -27,6 +26,12 @@ import warnings from functools import partial +try: + from numpy.typing import ArrayLike +except ImportError: + # numpy <1.20 + ArrayLike = np.ndarray + LOG = logging.getLogger(__name__) From 8a7f333f9c2ab75f92e04406c2bbff6e3664f8ed Mon Sep 17 00:00:00 2001 From: David Hoese Date: Thu, 22 Apr 2021 07:15:33 -0500 Subject: [PATCH 2/2] Move ArrayLike definition to satpy/_compat.py --- satpy/_compat.py | 7 +++++++ satpy/enhancements/__init__.py | 7 +------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/satpy/_compat.py b/satpy/_compat.py index 409261c697..ec3b0a5ffc 100644 --- a/satpy/_compat.py +++ b/satpy/_compat.py @@ -26,3 +26,10 @@ def cached_property(func): """Port back functools.cached_property.""" return property(lru_cache(maxsize=None)(func)) + + +try: + from numpy.typing import ArrayLike # noqa +except ImportError: + # numpy <1.20 + from numpy import ndarray as ArrayLike # noqa diff --git a/satpy/enhancements/__init__.py b/satpy/enhancements/__init__.py index cf6c5ea05a..a5609434c3 100644 --- a/satpy/enhancements/__init__.py +++ b/satpy/enhancements/__init__.py @@ -25,12 +25,7 @@ import logging import warnings from functools import partial - -try: - from numpy.typing import ArrayLike -except ImportError: - # numpy <1.20 - ArrayLike = np.ndarray +from satpy._compat import ArrayLike LOG = logging.getLogger(__name__)