Skip to content

Commit a15587d

Browse files
rthshoyer
authored andcommitted
FIX Don't raise a deprecation warning for xarray.ufuncs.{angle,iscomplex} (#2615)
* Don't raise a warning for xarray.ufuncs.angle * Update warning message
1 parent 57348ab commit a15587d

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

xarray/tests/test_ufuncs.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,41 @@ def test_xarray_ufuncs_deprecation():
172172
with pytest.warns(PendingDeprecationWarning, match='xarray.ufuncs'):
173173
xu.cos(xr.DataArray([0, 1]))
174174

175+
with pytest.warns(None) as record:
176+
xu.angle(xr.DataArray([0, 1]))
177+
record = [el.message for el in record
178+
if el.category == PendingDeprecationWarning]
179+
assert len(record) == 0
180+
181+
182+
@requires_np113
183+
@pytest.mark.filterwarnings('ignore::RuntimeWarning')
184+
@pytest.mark.parametrize(
185+
'name',
186+
[name for name in dir(xu)
187+
if (not name.startswith('_') and hasattr(np, name)
188+
and name not in ['print_function', 'absolute_import', 'division'])]
189+
)
190+
def test_numpy_ufuncs(name, request):
191+
x = xr.DataArray([1, 1])
192+
193+
np_func = getattr(np, name)
194+
if hasattr(np_func, 'nin') and np_func.nin == 2:
195+
args = (x, x)
196+
else:
197+
args = (x,)
198+
199+
y = np_func(*args)
200+
201+
if name in ['angle', 'iscomplex']:
202+
# these functions need to be handled with __array_function__ protocol
203+
assert isinstance(y, np.ndarray)
204+
elif name in ['frexp']:
205+
# np.frexp returns a tuple
206+
assert not isinstance(y, xr.DataArray)
207+
else:
208+
assert isinstance(y, xr.DataArray)
209+
175210

176211
def test_xarray_ufuncs_pickle():
177212
a = 1.0

xarray/ufuncs.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ def __init__(self, name):
4444
self._name = name
4545

4646
def __call__(self, *args, **kwargs):
47-
_warnings.warn(
48-
'xarray.ufuncs will be deprecated when xarray no longer supports '
49-
'versions of numpy older than v1.13. Instead, use numpy ufuncs '
50-
'directly.', PendingDeprecationWarning, stacklevel=2)
47+
if self._name not in ['angle', 'iscomplex']:
48+
_warnings.warn(
49+
'xarray.ufuncs will be deprecated when xarray no longer '
50+
'supports versions of numpy older than v1.17. Instead, use '
51+
'numpy ufuncs directly.',
52+
PendingDeprecationWarning, stacklevel=2)
5153

5254
new_args = args
5355
f = _dask_or_eager_func(self._name, array_args=slice(len(args)))

0 commit comments

Comments
 (0)