Skip to content

Commit 4d94858

Browse files
author
Joe Hamman
committed
further cleanup after merging in latest changes
1 parent 5dd029f commit 4d94858

File tree

7 files changed

+24
-75
lines changed

7 files changed

+24
-75
lines changed

xarray/backends/api.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@ def _validate_attrs(dataset):
9898
def check_attr(name, value):
9999
if isinstance(name, basestring):
100100
if not name:
101-
raise ValueError('Invalid name for attr: string must be length '
102-
'1 or greater for serialization to netCDF '
103-
'files')
101+
raise ValueError('Invalid name for attr: string must be '
102+
'length 1 or greater for serialization to '
103+
'netCDF files')
104104
else:
105105
raise TypeError("Invalid name for attr: {} must be a string for "
106106
"serialization to netCDF files".format(name))
107107

108108
if not isinstance(value, (basestring, Number, np.ndarray, np.number,
109109
list, tuple)):
110110
raise TypeError('Invalid value for attr: {} must be a number '
111-
'string, ndarray or a list/tuple of numbers/strings '
112-
'for serialization to netCDF '
111+
'string, ndarray or a list/tuple of '
112+
'numbers/strings for serialization to netCDF '
113113
'files'.format(value))
114114

115115
# Check attrs on the dataset itself
@@ -228,9 +228,11 @@ def maybe_decode_store(store, lock=False):
228228
try:
229229
from dask.base import tokenize
230230
except ImportError:
231-
import dask # raise the usual error if dask is entirely missing
231+
# raise the usual error if dask is entirely missing
232+
import dask
232233
if StrictVersion(dask.__version__) < StrictVersion('0.6'):
233-
raise ImportError('xarray requires dask version 0.6 or newer')
234+
raise ImportError(
235+
'xarray requires dask version 0.6 or newer')
234236
else:
235237
raise
236238

xarray/core/common.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ def where(self, cond, other=None, drop=False):
602602
Unimplemented placeholder for compatibility with future
603603
numpy / pandas versions
604604
drop : boolean, optional
605-
Coordinate labels that only correspond to NA values should be dropped
605+
Coordinate labels that only correspond to NA values should be
606+
dropped
606607
607608
Returns
608609
-------
@@ -677,8 +678,8 @@ def __enter__(self):
677678
def __exit__(self, exc_type, exc_value, traceback):
678679
self.close()
679680

680-
# this has no runtime function - these are listed so IDEs know these methods
681-
# are defined and don't warn on these operations
681+
# this has no runtime function - these are listed so IDEs know these
682+
# methods are defined and don't warn on these operations
682683
__lt__ = __le__ = __ge__ = __gt__ = __add__ = __sub__ = __mul__ = \
683684
__truediv__ = __floordiv__ = __mod__ = __pow__ = __and__ = __xor__ = \
684685
__or__ = __div__ = __eq__ = __ne__ = not_implemented

xarray/core/dataset.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
broadcast_variables)
2929
from .pycompat import (iteritems, basestring, OrderedDict,
3030
dask_array_type, range)
31-
from .combine import concat
3231
from .options import OPTIONS
3332

3433
# list of attributes of pd.DatetimeIndex that are ndarrays of time info
@@ -1221,7 +1220,6 @@ def isel_points(self, dim='points', **indexers):
12211220
Dataset.sel_points
12221221
DataArray.isel_points
12231222
"""
1224-
from .dataarray import DataArray
12251223

12261224
indexer_dims = set(indexers)
12271225

@@ -2097,7 +2095,7 @@ def reduce(self, func, dim=None, keep_attrs=False, numeric_only=False,
20972095
if name not in self.coords:
20982096
if (not numeric_only or
20992097
np.issubdtype(var.dtype, np.number) or
2100-
var.dtype == np.bool_):
2098+
(var.dtype == np.bool_)):
21012099
if len(reduce_dims) == 1:
21022100
# unpack dimensions for the benefit of functions
21032101
# like np.argmin which can't handle tuple arguments
@@ -2809,7 +2807,7 @@ def filter_by_attrs(self, **kwargs):
28092807
for attr_name, pattern in kwargs.items():
28102808
attr_value = variable.attrs.get(attr_name)
28112809
if ((callable(pattern) and pattern(attr_value))
2812-
or attr_value == pattern):
2810+
or attr_value == pattern):
28132811
selection.append(var_name)
28142812
return self[selection]
28152813

xarray/core/formatting.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
from pandas.tslib import OutOfBoundsDatetime
1717

1818
from .options import OPTIONS
19-
from .pycompat import (
20-
PY2, unicode_type, bytes_type, dask_array_type, OrderedDict)
19+
from .pycompat import PY2, unicode_type, bytes_type, dask_array_type
2120

2221

2322
def pretty_print(x, numchars):

xarray/core/npcompat.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ def nanprod(a, axis=None, dtype=None, out=None, keepdims=0):
252252

253253
def nancumsum(a, axis=None, dtype=None, out=None):
254254
"""
255-
Return the cumulative sum of array elements over a given axis treating Not a
256-
Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are
257-
encountered and leading NaNs are replaced by zeros.
255+
Return the cumulative sum of array elements over a given axis treating
256+
Not a Numbers (NaNs) as zero. The cumulative sum does not change when
257+
NaNs are encountered and leading NaNs are replaced by zeros.
258258
259259
Zeros are returned for slices that are all-NaN or empty.
260260
@@ -316,9 +316,9 @@ def nancumsum(a, axis=None, dtype=None, out=None):
316316

317317
def nancumprod(a, axis=None, dtype=None, out=None):
318318
"""
319-
Return the cumulative product of array elements over a given axis treating Not a
320-
Numbers (NaNs) as one. The cumulative product does not change when NaNs are
321-
encountered and leading NaNs are replaced by ones.
319+
Return the cumulative product of array elements over a given axis
320+
treating Not a Numbers (NaNs) as one. The cumulative product does not
321+
change when NaNs are encountered and leading NaNs are replaced by ones.
322322
323323
Ones are returned for slices that are all-NaN or empty.
324324

xarray/core/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def is_scalar(value):
189189
isinstance(value, (basestring, bytes_type)) or not
190190
isinstance(value, Iterable))
191191

192+
192193
def is_valid_numpy_dtype(dtype):
193194
try:
194195
np.dtype(dtype)

xarray/tests/__init__.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from numpy.testing import assert_array_equal
1010
import pytest
1111

12-
from xarray.core import utils, ops
12+
from xarray.core import utils
1313
from xarray.core.pycompat import PY3
1414
from xarray.testing import assert_equal, assert_identical, assert_allclose
1515

@@ -168,58 +168,6 @@ def assertDataArrayAllClose(self, ar1, ar2, rtol=1e-05, atol=1e-08):
168168
assert_allclose(ar1, ar2, rtol=rtol, atol=atol)
169169

170170

171-
def assert_xarray_equal(a, b):
172-
import xarray as xr
173-
___tracebackhide__ = True # noqa: F841
174-
assert type(a) == type(b)
175-
if isinstance(a, (xr.Variable, xr.DataArray, xr.Dataset)):
176-
assert a.equals(b), '{}\n{}'.format(a, b)
177-
else:
178-
raise TypeError('{} not supported by assertion comparison'
179-
.format(type(a)))
180-
181-
182-
def assert_xarray_identical(a, b):
183-
import xarray as xr
184-
___tracebackhide__ = True # noqa: F841
185-
assert type(a) == type(b)
186-
if isinstance(a, xr.DataArray):
187-
assert a.name == b.name
188-
assert_xarray_identical(a._to_temp_dataset(), b._to_temp_dataset())
189-
elif isinstance(a, (xr.Dataset, xr.Variable)):
190-
assert a.identical(b), '{}\n{}'.format(a, b)
191-
else:
192-
raise TypeError('{} not supported by assertion comparison'
193-
.format(type(a)))
194-
195-
196-
def assert_xarray_allclose(a, b, rtol=1e-05, atol=1e-08):
197-
import xarray as xr
198-
___tracebackhide__ = True # noqa: F841
199-
assert type(a) == type(b)
200-
if isinstance(a, xr.Variable):
201-
assert a.dims == b.dims
202-
allclose = data_allclose_or_equiv(
203-
a.values, b.values, rtol=rtol, atol=atol)
204-
assert allclose, '{}\n{}'.format(a.values, b.values)
205-
elif isinstance(a, xr.DataArray):
206-
assert_xarray_allclose(a.variable, b.variable)
207-
for v in a.coords.variables:
208-
# can't recurse with this function as coord is sometimes a DataArray,
209-
# so call into data_allclose_or_equiv directly
210-
allclose = data_allclose_or_equiv(
211-
a.coords[v].values, b.coords[v].values, rtol=rtol, atol=atol)
212-
assert allclose, '{}\n{}'.format(a.coords[v].values, b.coords[v].values)
213-
elif isinstance(a, xr.Dataset):
214-
assert sorted(a, key=str) == sorted(b, key=str)
215-
for k in list(a.variables) + list(a.coords):
216-
assert_xarray_allclose(a[k], b[k], rtol=rtol, atol=atol)
217-
218-
else:
219-
raise TypeError('{} not supported by assertion comparison'
220-
.format(type(a)))
221-
222-
223171
class UnexpectedDataAccess(Exception):
224172
pass
225173

0 commit comments

Comments
 (0)