Skip to content

Commit 8d9e897

Browse files
authored
remove nep18 compatibility code (#5064)
1 parent fdf024c commit 8d9e897

File tree

7 files changed

+1
-45
lines changed

7 files changed

+1
-45
lines changed

xarray/core/npcompat.py

-15
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,6 @@ def moveaxis(a, source, destination):
8484
DTypeLike = Union[np.dtype, str] # type: ignore
8585

8686

87-
# from dask/array/utils.py
88-
def _is_nep18_active():
89-
class A:
90-
def __array_function__(self, *args, **kwargs):
91-
return True
92-
93-
try:
94-
return np.concatenate([A()])
95-
except ValueError:
96-
return False
97-
98-
99-
IS_NEP18_ACTIVE = _is_nep18_active()
100-
101-
10287
if LooseVersion(np.__version__) >= "1.20.0":
10388
sliding_window_view = np.lib.stride_tricks.sliding_window_view
10489
else:

xarray/core/variable.py

+1-11
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
VectorizedIndexer,
3333
as_indexable,
3434
)
35-
from .npcompat import IS_NEP18_ACTIVE
3635
from .options import _get_keep_attrs
3736
from .pycompat import (
3837
cupy_array_type,
@@ -242,16 +241,7 @@ def as_compatible_data(data, fastpath=False):
242241

243242
if not isinstance(data, np.ndarray):
244243
if hasattr(data, "__array_function__"):
245-
if IS_NEP18_ACTIVE:
246-
return data
247-
else:
248-
raise TypeError(
249-
"Got an NumPy-like array type providing the "
250-
"__array_function__ protocol but NEP18 is not enabled. "
251-
"Check that numpy >= v1.16 and that the environment "
252-
'variable "NUMPY_EXPERIMENTAL_ARRAY_FUNCTION" is set to '
253-
'"1"'
254-
)
244+
return data
255245

256246
# validate whether the data is valid data types.
257247
data = np.asarray(data)

xarray/tests/test_dataset.py

-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from xarray.coding.cftimeindex import CFTimeIndex
2929
from xarray.core import dtypes, indexing, utils
3030
from xarray.core.common import duck_array_ops, full_like
31-
from xarray.core.npcompat import IS_NEP18_ACTIVE
3231
from xarray.core.pycompat import integer_types
3332
from xarray.core.utils import is_scalar
3433

@@ -320,7 +319,6 @@ def test_unicode_data(self):
320319
actual = str(data)
321320
assert expected == actual
322321

323-
@pytest.mark.skipif(not IS_NEP18_ACTIVE, reason="requires __array_function__")
324322
def test_repr_nep18(self):
325323
class Array:
326324
def __init__(self):

xarray/tests/test_formatting.py

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import xarray as xr
99
from xarray.core import formatting
10-
from xarray.core.npcompat import IS_NEP18_ACTIVE
1110

1211
from . import raises_regex
1312

@@ -395,7 +394,6 @@ def test_array_repr(self):
395394
assert actual == expected
396395

397396

398-
@pytest.mark.skipif(not IS_NEP18_ACTIVE, reason="requires __array_function__")
399397
def test_inline_variable_array_repr_custom_repr():
400398
class CustomArray:
401399
def __init__(self, value, attr):

xarray/tests/test_sparse.py

-6
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@
88
import xarray as xr
99
import xarray.ufuncs as xu
1010
from xarray import DataArray, Variable
11-
from xarray.core.npcompat import IS_NEP18_ACTIVE
1211
from xarray.core.pycompat import sparse_array_type
1312

1413
from . import assert_equal, assert_identical, requires_dask
1514

1615
param = pytest.param
1716
xfail = pytest.mark.xfail
1817

19-
if not IS_NEP18_ACTIVE:
20-
pytest.skip(
21-
"NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled", allow_module_level=True
22-
)
23-
2418
sparse = pytest.importorskip("sparse")
2519

2620

xarray/tests/test_testing.py

-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import pytest
55

66
import xarray as xr
7-
from xarray.core.npcompat import IS_NEP18_ACTIVE
87

98
from . import has_dask
109

@@ -99,10 +98,6 @@ def test_assert_duckarray_equal_failing(duckarray, obj1, obj2):
9998
pytest.param(
10099
np.array,
101100
id="numpy",
102-
marks=pytest.mark.skipif(
103-
not IS_NEP18_ACTIVE,
104-
reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled",
105-
),
106101
),
107102
pytest.param(
108103
dask_from_array,

xarray/tests/test_units.py

-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
import xarray as xr
99
from xarray.core import dtypes
10-
from xarray.core.npcompat import IS_NEP18_ACTIVE
1110

1211
from . import assert_allclose, assert_duckarray_allclose, assert_equal, assert_identical
1312
from .test_variable import _PAD_XR_NP_ARGS
@@ -23,9 +22,6 @@
2322

2423

2524
pytestmark = [
26-
pytest.mark.skipif(
27-
not IS_NEP18_ACTIVE, reason="NUMPY_EXPERIMENTAL_ARRAY_FUNCTION is not enabled"
28-
),
2925
pytest.mark.filterwarnings("error::pint.UnitStrippedWarning"),
3026
]
3127

0 commit comments

Comments
 (0)