Skip to content

Commit 93d6963

Browse files
author
Joe Hamman
authored
Merge pull request #1242 from jhamman/cleanup
Cleanup
2 parents 588339c + 4d94858 commit 93d6963

File tree

11 files changed

+39
-48
lines changed

11 files changed

+39
-48
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/alignment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from collections import defaultdict
77

88
import numpy as np
9-
import pandas as pd
109

1110
from . import ops, utils
1211
from .common import _maybe_promote

xarray/core/common.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55
import pandas as pd
66

7-
from .pycompat import (basestring, suppress, dask_array_type, OrderedDict)
7+
from .pycompat import basestring, suppress, dask_array_type, OrderedDict
88
from . import formatting
99
from .utils import SortedKeysDict, not_implemented, Frozen
1010

@@ -599,9 +599,11 @@ def where(self, cond, other=None, drop=False):
599599
----------
600600
cond : boolean DataArray or Dataset
601601
other : unimplemented, optional
602-
Unimplemented placeholder for compatibility with future numpy / pandas versions
602+
Unimplemented placeholder for compatibility with future
603+
numpy / pandas versions
603604
drop : boolean, optional
604-
Coordinate labels that only correspond to NA values should be dropped
605+
Coordinate labels that only correspond to NA values should be
606+
dropped
605607
606608
Returns
607609
-------
@@ -633,7 +635,8 @@ def where(self, cond, other=None, drop=False):
633635
* y (y) int64 0 1 2 3 4
634636
"""
635637
if other is not None:
636-
raise NotImplementedError("The optional argument 'other' has not yet been implemented")
638+
raise NotImplementedError("The optional argument 'other' has not "
639+
"yet been implemented")
637640

638641
if drop:
639642
from .dataarray import DataArray
@@ -675,11 +678,11 @@ def __enter__(self):
675678
def __exit__(self, exc_type, exc_value, traceback):
676679
self.close()
677680

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

684687

685688
def _maybe_promote(dtype):

xarray/core/dataset.py

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

3533
# list of attributes of pd.DatetimeIndex that are ndarrays of time info
@@ -154,8 +152,8 @@ def merge_indexes(
154152
for n in var_names:
155153
names.append(n)
156154
var = variables[n]
157-
if (current_index_variable is not None and
158-
var.dims != current_index_variable.dims):
155+
if ((current_index_variable is not None) and
156+
(var.dims != current_index_variable.dims)):
159157
raise ValueError(
160158
"dimension mismatch between %r %s and %r %s"
161159
% (dim, current_index_variable.dims, n, var.dims))
@@ -1222,7 +1220,6 @@ def isel_points(self, dim='points', **indexers):
12221220
Dataset.sel_points
12231221
DataArray.isel_points
12241222
"""
1225-
from .dataarray import DataArray
12261223

12271224
indexer_dims = set(indexers)
12281225

@@ -2098,7 +2095,7 @@ def reduce(self, func, dim=None, keep_attrs=False, numeric_only=False,
20982095
if name not in self.coords:
20992096
if (not numeric_only or
21002097
np.issubdtype(var.dtype, np.number) or
2101-
var.dtype == np.bool_):
2098+
(var.dtype == np.bool_)):
21022099
if len(reduce_dims) == 1:
21032100
# unpack dimensions for the benefit of functions
21042101
# like np.argmin which can't handle tuple arguments
@@ -2810,7 +2807,7 @@ def filter_by_attrs(self, **kwargs):
28102807
for attr_name, pattern in kwargs.items():
28112808
attr_value = variable.attrs.get(attr_name)
28122809
if ((callable(pattern) and pattern(attr_value))
2813-
or attr_value == pattern):
2810+
or attr_value == pattern):
28142811
selection.append(var_name)
28152812
return self[selection]
28162813

xarray/core/formatting.py

Lines changed: 2 additions & 3 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, basestring)
19+
from .pycompat import PY2, unicode_type, bytes_type, dask_array_type
2120

2221

2322
def pretty_print(x, numchars):
@@ -49,7 +48,7 @@ def ensure_valid_repr(string):
4948
On Python 2, this means we need to convert unicode to bytes. We won't need
5049
this function once we drop Python 2.7 support.
5150
"""
52-
if PY2 and isinstance(string, unicode):
51+
if PY2 and isinstance(string, unicode_type):
5352
string = string.encode('utf-8')
5453
return string
5554

xarray/core/groupby.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def _consolidate_slices(slices):
8282
"""Consolidate adjacent slices in a list of slices.
8383
"""
8484
result = []
85+
last_slice = slice(None)
8586
for slice_ in slices:
8687
if not isinstance(slice_, slice):
8788
raise ValueError('list element is not a slice: %r' % slice_)

xarray/core/npcompat.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ def _maybe_view_as_subclass(original_array, new_array):
2424
new_array.__array_finalize__(original_array)
2525
return new_array
2626

27-
2827
def _broadcast_to(array, shape, subok, readonly):
2928
shape = tuple(shape) if np.iterable(shape) else (shape,)
3029
array = np.array(array, copy=False, subok=subok)
@@ -41,7 +40,6 @@ def _broadcast_to(array, shape, subok, readonly):
4140
result.flags.writeable = True
4241
return result
4342

44-
4543
def broadcast_to(array, shape, subok=False):
4644
"""Broadcast an array to a new shape.
4745
@@ -78,7 +76,6 @@ def broadcast_to(array, shape, subok=False):
7876
"""
7977
return _broadcast_to(array, shape, subok=subok, readonly=True)
8078

81-
8279
def stack(arrays, axis=0):
8380
"""
8481
Join a sequence of arrays along a new axis.
@@ -143,7 +140,6 @@ def stack(arrays, axis=0):
143140
expanded_arrays = [arr[sl] for arr in arrays]
144141
return np.concatenate(expanded_arrays, axis=axis)
145142

146-
147143
def _replace_nan(a, val):
148144
"""
149145
If `a` is of inexact type, make a copy of `a`, replace NaNs with
@@ -185,7 +181,6 @@ def _replace_nan(a, val):
185181
np.copyto(a, val, where=mask)
186182
return a, mask
187183

188-
189184
def nanprod(a, axis=None, dtype=None, out=None, keepdims=0):
190185
"""
191186
Return the product of array elements over a given axis treating Not a
@@ -255,12 +250,11 @@ def nanprod(a, axis=None, dtype=None, out=None, keepdims=0):
255250
a, mask = _replace_nan(a, 1)
256251
return np.prod(a, axis=axis, dtype=dtype, out=out, keepdims=keepdims)
257252

258-
259253
def nancumsum(a, axis=None, dtype=None, out=None):
260254
"""
261-
Return the cumulative sum of array elements over a given axis treating Not a
262-
Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are
263-
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.
264258
265259
Zeros are returned for slices that are all-NaN or empty.
266260
@@ -320,12 +314,11 @@ def nancumsum(a, axis=None, dtype=None, out=None):
320314
a, mask = _replace_nan(a, 0)
321315
return np.cumsum(a, axis=axis, dtype=dtype, out=out)
322316

323-
324317
def nancumprod(a, axis=None, dtype=None, out=None):
325318
"""
326-
Return the cumulative product of array elements over a given axis treating Not a
327-
Numbers (NaNs) as one. The cumulative product does not change when NaNs are
328-
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.
329322
330323
Ones are returned for slices that are all-NaN or empty.
331324

xarray/core/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def equivalent(first, second):
101101
if isinstance(first, np.ndarray) or isinstance(second, np.ndarray):
102102
return ops.array_equiv(first, second)
103103
else:
104-
return (first is second or
105-
first == second or
104+
return ((first is second) or
105+
(first == second) or
106106
(pd.isnull(first) and pd.isnull(second)))
107107

108108

xarray/core/variable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,8 @@ def reduce(self, func, dim=None, axis=None, keep_attrs=False,
896896

897897
if getattr(func, 'keep_dims', False):
898898
if dim is None and axis is None:
899-
raise ValueError("must supply either single 'dim' or 'axis' argument to %s"
900-
% (func.__name__))
899+
raise ValueError("must supply either single 'dim' or 'axis' "
900+
"argument to %s" % (func.__name__))
901901

902902
if dim is not None:
903903
axis = self.get_axis_num(dim)

xarray/plot/plot.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ def hist(darray, figsize=None, size=None, aspect=None, ax=None, **kwargs):
227227
Additional keyword arguments to matplotlib.pyplot.hist
228228
229229
"""
230-
import matplotlib.pyplot as plt
231-
232230
ax = get_axis(figsize, size, aspect, ax)
233231

234232
no_nan = np.ravel(darray.values)

xarray/tests/__init__.py

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

12-
from xarray.core import utils, nputils, ops
13-
from xarray.core.variable import as_variable
12+
from xarray.core import utils
1413
from xarray.core.pycompat import PY3
1514
from xarray.testing import assert_equal, assert_identical, assert_allclose
1615

0 commit comments

Comments
 (0)