From 8d9e897dcabd6569a778a97fc3446143d9ed1604 Mon Sep 17 00:00:00 2001 From: keewis Date: Fri, 26 Mar 2021 23:00:52 +0100 Subject: [PATCH] remove nep18 compatibility code (#5064) --- xarray/core/npcompat.py | 15 --------------- xarray/core/variable.py | 12 +----------- xarray/tests/test_dataset.py | 2 -- xarray/tests/test_formatting.py | 2 -- xarray/tests/test_sparse.py | 6 ------ xarray/tests/test_testing.py | 5 ----- xarray/tests/test_units.py | 4 ---- 7 files changed, 1 insertion(+), 45 deletions(-) diff --git a/xarray/core/npcompat.py b/xarray/core/npcompat.py index 4016fe44ca6..b319648886e 100644 --- a/xarray/core/npcompat.py +++ b/xarray/core/npcompat.py @@ -84,21 +84,6 @@ def moveaxis(a, source, destination): DTypeLike = Union[np.dtype, str] # type: ignore -# from dask/array/utils.py -def _is_nep18_active(): - class A: - def __array_function__(self, *args, **kwargs): - return True - - try: - return np.concatenate([A()]) - except ValueError: - return False - - -IS_NEP18_ACTIVE = _is_nep18_active() - - if LooseVersion(np.__version__) >= "1.20.0": sliding_window_view = np.lib.stride_tricks.sliding_window_view else: diff --git a/xarray/core/variable.py b/xarray/core/variable.py index 272d7c355ea..2e97fad91b2 100644 --- a/xarray/core/variable.py +++ b/xarray/core/variable.py @@ -32,7 +32,6 @@ VectorizedIndexer, as_indexable, ) -from .npcompat import IS_NEP18_ACTIVE from .options import _get_keep_attrs from .pycompat import ( cupy_array_type, @@ -242,16 +241,7 @@ def as_compatible_data(data, fastpath=False): if not isinstance(data, np.ndarray): if hasattr(data, "__array_function__"): - if IS_NEP18_ACTIVE: - return data - else: - raise TypeError( - "Got an NumPy-like array type providing the " - "__array_function__ protocol but NEP18 is not enabled. " - "Check that numpy >= v1.16 and that the environment " - 'variable "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION" is set to ' - '"1"' - ) + return data # validate whether the data is valid data types. data = np.asarray(data) diff --git a/xarray/tests/test_dataset.py b/xarray/tests/test_dataset.py index 52df7603034..fb15f15df1a 100644 --- a/xarray/tests/test_dataset.py +++ b/xarray/tests/test_dataset.py @@ -28,7 +28,6 @@ from xarray.coding.cftimeindex import CFTimeIndex from xarray.core import dtypes, indexing, utils from xarray.core.common import duck_array_ops, full_like -from xarray.core.npcompat import IS_NEP18_ACTIVE from xarray.core.pycompat import integer_types from xarray.core.utils import is_scalar @@ -320,7 +319,6 @@ def test_unicode_data(self): actual = str(data) assert expected == actual - @pytest.mark.skipif(not IS_NEP18_ACTIVE, reason="requires __array_function__") def test_repr_nep18(self): class Array: def __init__(self): diff --git a/xarray/tests/test_formatting.py b/xarray/tests/test_formatting.py index f2facf5b481..889e76cf99f 100644 --- a/xarray/tests/test_formatting.py +++ b/xarray/tests/test_formatting.py @@ -7,7 +7,6 @@ import xarray as xr from xarray.core import formatting -from xarray.core.npcompat import IS_NEP18_ACTIVE from . import raises_regex @@ -395,7 +394,6 @@ def test_array_repr(self): assert actual == expected -@pytest.mark.skipif(not IS_NEP18_ACTIVE, reason="requires __array_function__") def test_inline_variable_array_repr_custom_repr(): class CustomArray: def __init__(self, value, attr): diff --git a/xarray/tests/test_sparse.py b/xarray/tests/test_sparse.py index 07d8df7a5a5..7ab5fbeb10a 100644 --- a/xarray/tests/test_sparse.py +++ b/xarray/tests/test_sparse.py @@ -8,7 +8,6 @@ import xarray as xr import xarray.ufuncs as xu from xarray import DataArray, Variable -from xarray.core.npcompat import IS_NEP18_ACTIVE from xarray.core.pycompat import sparse_array_type from . import assert_equal, assert_identical, requires_dask @@ -16,11 +15,6 @@ param = pytest.param xfail = pytest.mark.xfail -if not IS_NEP18_ACTIVE: - pytest.skip( - "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled", allow_module_level=True - ) - sparse = pytest.importorskip("sparse") diff --git a/xarray/tests/test_testing.py b/xarray/tests/test_testing.py index b6dec846c54..7df7a45a04e 100644 --- a/xarray/tests/test_testing.py +++ b/xarray/tests/test_testing.py @@ -4,7 +4,6 @@ import pytest import xarray as xr -from xarray.core.npcompat import IS_NEP18_ACTIVE from . import has_dask @@ -99,10 +98,6 @@ def test_assert_duckarray_equal_failing(duckarray, obj1, obj2): pytest.param( np.array, id="numpy", - marks=pytest.mark.skipif( - not IS_NEP18_ACTIVE, - reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled", - ), ), pytest.param( dask_from_array, diff --git a/xarray/tests/test_units.py b/xarray/tests/test_units.py index 8b7835e5da6..cc3c1a292ec 100644 --- a/xarray/tests/test_units.py +++ b/xarray/tests/test_units.py @@ -7,7 +7,6 @@ import xarray as xr from xarray.core import dtypes -from xarray.core.npcompat import IS_NEP18_ACTIVE from . import assert_allclose, assert_duckarray_allclose, assert_equal, assert_identical from .test_variable import _PAD_XR_NP_ARGS @@ -23,9 +22,6 @@ pytestmark = [ - pytest.mark.skipif( - not IS_NEP18_ACTIVE, reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled" - ), pytest.mark.filterwarnings("error::pint.UnitStrippedWarning"), ]