Skip to content

fixes for warnings related to unit tests and nan comparisons #1657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 29, 2017
14 changes: 9 additions & 5 deletions xarray/core/dataarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,9 @@ def __array_wrap__(self, obj, context=None):
def _unary_op(f):
@functools.wraps(f)
def func(self, *args, **kwargs):
return self.__array_wrap__(f(self.variable.data, *args, **kwargs))
with np.errstate(all='ignore'):
return self.__array_wrap__(f(self.variable.data, *args,
**kwargs))

return func

Expand All @@ -1588,9 +1590,10 @@ def func(self, other):
other_variable = getattr(other, 'variable', other)
other_coords = getattr(other, 'coords', None)

variable = (f(self.variable, other_variable)
if not reflexive
else f(other_variable, self.variable))
with np.errstate(all='ignore'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this here -- this should be caught at the level of the Variable wrapper.

variable = (f(self.variable, other_variable)
if not reflexive
else f(other_variable, self.variable))
coords = self.coords._merge_raw(other_coords)
name = self._result_name(other)

Expand All @@ -1612,7 +1615,8 @@ def func(self, other):
other_coords = getattr(other, 'coords', None)
other_variable = getattr(other, 'variable', other)
with self.coords._merge_inplace(other_coords):
f(self.variable, other_variable)
with np.errstate(all='ignore'):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also probably unneeded

f(self.variable, other_variable)
return self

return func
Expand Down
3 changes: 2 additions & 1 deletion xarray/core/pycompat.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def itervalues(d):
from functools import reduce
import builtins
from urllib.request import urlretrieve
from inspect import getfullargspec as getargspec
else: # pragma: no cover
# Python 2
basestring = basestring # noqa
Expand All @@ -43,7 +44,7 @@ def itervalues(d):
reduce = reduce
import __builtin__ as builtins
from urllib import urlretrieve

from inspect import getargspec
try:
from cyordereddict import OrderedDict
except ImportError: # pragma: no cover
Expand Down
13 changes: 8 additions & 5 deletions xarray/core/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,8 @@ def __array_wrap__(self, obj, context=None):
def _unary_op(f):
@functools.wraps(f)
def func(self, *args, **kwargs):
return self.__array_wrap__(f(self.data, *args, **kwargs))
with np.errstate(all='ignore'):
return self.__array_wrap__(f(self.data, *args, **kwargs))
return func

@staticmethod
Expand All @@ -1364,9 +1365,10 @@ def func(self, other):
if isinstance(other, (xr.DataArray, xr.Dataset)):
return NotImplemented
self_data, other_data, dims = _broadcast_compat_data(self, other)
new_data = (f(self_data, other_data)
if not reflexive
else f(other_data, self_data))
with np.errstate(all='ignore'):
new_data = (f(self_data, other_data)
if not reflexive
else f(other_data, self_data))
result = Variable(dims, new_data)
return result
return func
Expand All @@ -1381,7 +1383,8 @@ def func(self, other):
if dims != self.dims:
raise ValueError('dimensions cannot change for in-place '
'operations')
self.values = f(self_data, other_data)
with np.errstate(all='ignore'):
self.values = f(self_data, other_data)
return self
return func

Expand Down
4 changes: 2 additions & 2 deletions xarray/plot/facetgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
from __future__ import division
from __future__ import print_function

import inspect
import warnings
import itertools
import functools

import numpy as np

from ..core.pycompat import getargspec
from ..core.formatting import format_item
from .utils import _determine_cmap_params, _infer_xy_labels

Expand Down Expand Up @@ -227,7 +227,7 @@ def map_dataarray(self, func, x, y, **kwargs):
'filled': func.__name__ != 'contour',
}

cmap_args = inspect.getargspec(_determine_cmap_params).args
cmap_args = getargspec(_determine_cmap_params).args
cmap_kwargs.update((a, kwargs[a]) for a in cmap_args if a in kwargs)

cmap_params = _determine_cmap_params(**cmap_kwargs)
Expand Down
6 changes: 3 additions & 3 deletions xarray/tests/test_accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
import pandas as pd

from . import TestCase, requires_dask
from . import TestCase, requires_dask, raises_regex


class TestDatetimeAccessor(TestCase):
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_not_datetime_type(self):
nontime_data = self.data.copy()
int_data = np.arange(len(self.data.time)).astype('int8')
nontime_data['time'].values = int_data
with self.assertRaisesRegexp(TypeError, 'dt'):
with raises_regex(TypeError, 'dt'):
nontime_data.time.dt

@requires_dask
Expand Down Expand Up @@ -93,4 +93,4 @@ def test_seasons(self):
"SON", "SON", "SON", "DJF"]
seasons = xr.DataArray(seasons)

self.assertArrayEqual(seasons.values, dates.dt.season.values)
self.assertArrayEqual(seasons.values, dates.dt.season.values)
Loading