Skip to content

Commit

Permalink
remove nep18 compatibility code (pydata#5064)
Browse files Browse the repository at this point in the history
  • Loading branch information
keewis authored Mar 26, 2021
1 parent fdf024c commit 8d9e897
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 45 deletions.
15 changes: 0 additions & 15 deletions xarray/core/npcompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 1 addition & 11 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions xarray/tests/test_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
2 changes: 0 additions & 2 deletions xarray/tests/test_formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down
6 changes: 0 additions & 6 deletions xarray/tests/test_sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
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

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")


Expand Down
5 changes: 0 additions & 5 deletions xarray/tests/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import pytest

import xarray as xr
from xarray.core.npcompat import IS_NEP18_ACTIVE

from . import has_dask

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 0 additions & 4 deletions xarray/tests/test_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"),
]

Expand Down

0 comments on commit 8d9e897

Please sign in to comment.