Skip to content

Commit 7293545

Browse files
committed
Xarray is now flake8-clean with dask settings
1 parent 76e4fea commit 7293545

10 files changed

+69
-73
lines changed

xarray/backends/zarr.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def _replace_slices_with_arrays(key, shape):
7171
slice_count += 1
7272
else:
7373
assert isinstance(k, np.ndarray)
74-
k = k[(slice(None),) * array_subspace_size
75-
+ (np.newaxis,) * num_slices]
74+
k = k[(slice(None),) * array_subspace_size +
75+
(np.newaxis,) * num_slices]
7676
new_key.append(k)
7777
return tuple(new_key)
7878

xarray/core/dataarray.py

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from .accessors import DatetimeAccessor
2020
from .alignment import align, reindex_like_indexers
2121
from .common import AbstractArray, BaseDataObject
22-
from .computation import apply_ufunc
2322
from .coordinates import (DataArrayCoordinates, LevelCoordinatesSource,
2423
Indexes, assert_coordinate_consistent,
2524
remap_label_indexers)

xarray/plot/plot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ def line(darray, *args, **kwargs):
206206
xlabel, = darray.dims
207207
if x is not None and xlabel != x:
208208
raise ValueError('Input does not have specified dimension'
209-
+ ' {!r}'.format(x))
209+
' {!r}'.format(x))
210210

211211
x = darray.coords[xlabel]
212212

xarray/tests/test_backends.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -1195,8 +1195,8 @@ def test_hidden_zarr_keys(self):
11951195
# JSON only has a single array type, which maps to list in Python.
11961196
# In contrast, dims in xarray is always a tuple.
11971197
for var in expected.variables.keys():
1198-
assert (zarr_group[var].attrs[self.DIMENSION_KEY]
1199-
== list(expected[var].dims))
1198+
assert (zarr_group[var].attrs[self.DIMENSION_KEY] ==
1199+
list(expected[var].dims))
12001200

12011201
with xr.decode_cf(store) as actual:
12021202
# make sure it is hidden
@@ -2426,7 +2426,7 @@ def test_ENVI_tags(self):
24262426
with create_tmp_file(suffix='.dat') as tmp_file:
24272427
# data
24282428
nx, ny, nz = 4, 3, 3
2429-
data = np.arange(nx*ny*nz,
2429+
data = np.arange(nx * ny * nz,
24302430
dtype=rasterio.float32).reshape(nz, ny, nx)
24312431
transform = from_origin(5000, 80000, 1000, 2000.)
24322432
with rasterio.open(
@@ -2437,25 +2437,22 @@ def test_ENVI_tags(self):
24372437
transform=transform,
24382438
dtype=rasterio.float32) as s:
24392439
s.update_tags(
2440-
ns='ENVI',
2441-
description='{Tagged file}',
2442-
wavelength='{123.000000, 234.234000, 345.345678}',
2443-
fwhm='{1.000000, 0.234000, 0.000345}')
2440+
ns='ENVI',
2441+
description='{Tagged file}',
2442+
wavelength='{123.000000, 234.234000, 345.345678}',
2443+
fwhm='{1.000000, 0.234000, 0.000345}')
24442444
s.write(data)
24452445
dx, dy = s.res[0], -s.res[1]
24462446

24472447
# Tests
2448-
expected = DataArray(data, dims=('band', 'y', 'x'),
2449-
coords={
2450-
'band': [1, 2, 3],
2451-
'y': -np.arange(ny) * 2000 + 80000 + dy/2,
2452-
'x': np.arange(nx) * 1000 + 5000 + dx/2,
2453-
'wavelength': (
2454-
'band',
2455-
np.array([123, 234.234, 345.345678])),
2456-
'fwhm': (
2457-
'band',
2458-
np.array([1, 0.234, 0.000345]))})
2448+
coords = {
2449+
'band': [1, 2, 3],
2450+
'y': -np.arange(ny) * 2000 + 80000 + dy / 2,
2451+
'x': np.arange(nx) * 1000 + 5000 + dx / 2,
2452+
'wavelength': ('band', np.array([123, 234.234, 345.345678])),
2453+
'fwhm': ('band', np.array([1, 0.234, 0.000345])),
2454+
}
2455+
expected = DataArray(data, dims=('band', 'y', 'x'), coords=coords)
24592456

24602457
with xr.open_rasterio(tmp_file) as rioda:
24612458
assert_allclose(rioda, expected)

xarray/tests/test_coding.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import numpy as np
2-
import pytest
32

43
import xarray as xr
54
from xarray.core.pycompat import suppress
65
from xarray.coding import variables
76

8-
from . import requires_dask, raises_regex, assert_identical
7+
from . import requires_dask, assert_identical
98

109
with suppress(ImportError):
1110
import dask.array as da

xarray/tests/test_coding_times.py

+29-29
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,29 @@ class TestDatetime(TestCase):
2424
def test_cf_datetime(self):
2525
import netCDF4 as nc4
2626
for num_dates, units in [
27-
(np.arange(10), 'days since 2000-01-01'),
28-
(np.arange(10).reshape(2, 5), 'days since 2000-01-01'),
29-
(12300 + np.arange(5), 'hours since 1680-01-01 00:00:00'),
30-
# here we add a couple minor formatting errors to test
31-
# the robustness of the parsing algorithm.
32-
(12300 + np.arange(5), 'hour since 1680-01-01 00:00:00'),
33-
(12300 + np.arange(5), u'Hour since 1680-01-01 00:00:00'),
34-
(12300 + np.arange(5), ' Hour since 1680-01-01 00:00:00 '),
35-
(10, 'days since 2000-01-01'),
36-
([10], 'daYs since 2000-01-01'),
37-
([[10]], 'days since 2000-01-01'),
38-
([10, 10], 'days since 2000-01-01'),
39-
(np.array(10), 'days since 2000-01-01'),
40-
(0, 'days since 1000-01-01'),
41-
([0], 'days since 1000-01-01'),
42-
([[0]], 'days since 1000-01-01'),
43-
(np.arange(2), 'days since 1000-01-01'),
44-
(np.arange(0, 100000, 20000), 'days since 1900-01-01'),
45-
(17093352.0, 'hours since 1-1-1 00:00:0.0'),
46-
([0.5, 1.5], 'hours since 1900-01-01T00:00:00'),
47-
(0, 'milliseconds since 2000-01-01T00:00:00'),
48-
(0, 'microseconds since 2000-01-01T00:00:00'),
49-
]:
27+
(np.arange(10), 'days since 2000-01-01'),
28+
(np.arange(10).reshape(2, 5), 'days since 2000-01-01'),
29+
(12300 + np.arange(5), 'hours since 1680-01-01 00:00:00'),
30+
# here we add a couple minor formatting errors to test
31+
# the robustness of the parsing algorithm.
32+
(12300 + np.arange(5), 'hour since 1680-01-01 00:00:00'),
33+
(12300 + np.arange(5), u'Hour since 1680-01-01 00:00:00'),
34+
(12300 + np.arange(5), ' Hour since 1680-01-01 00:00:00 '),
35+
(10, 'days since 2000-01-01'),
36+
([10], 'daYs since 2000-01-01'),
37+
([[10]], 'days since 2000-01-01'),
38+
([10, 10], 'days since 2000-01-01'),
39+
(np.array(10), 'days since 2000-01-01'),
40+
(0, 'days since 1000-01-01'),
41+
([0], 'days since 1000-01-01'),
42+
([[0]], 'days since 1000-01-01'),
43+
(np.arange(2), 'days since 1000-01-01'),
44+
(np.arange(0, 100000, 20000), 'days since 1900-01-01'),
45+
(17093352.0, 'hours since 1-1-1 00:00:0.0'),
46+
([0.5, 1.5], 'hours since 1900-01-01T00:00:00'),
47+
(0, 'milliseconds since 2000-01-01T00:00:00'),
48+
(0, 'microseconds since 2000-01-01T00:00:00'),
49+
]:
5050
for calendar in ['standard', 'gregorian', 'proleptic_gregorian']:
5151
expected = _ensure_naive_tz(
5252
nc4.num2date(num_dates, units, calendar))
@@ -224,12 +224,12 @@ def test_decode_non_standard_calendar_fallback(self):
224224
@requires_netCDF4
225225
def test_cf_datetime_nan(self):
226226
for num_dates, units, expected_list in [
227-
([np.nan], 'days since 2000-01-01', ['NaT']),
228-
([np.nan, 0], 'days since 2000-01-01',
229-
['NaT', '2000-01-01T00:00:00Z']),
230-
([np.nan, 0, 1], 'days since 2000-01-01',
231-
['NaT', '2000-01-01T00:00:00Z', '2000-01-02T00:00:00Z']),
232-
]:
227+
([np.nan], 'days since 2000-01-01', ['NaT']),
228+
([np.nan, 0], 'days since 2000-01-01',
229+
['NaT', '2000-01-01T00:00:00Z']),
230+
([np.nan, 0, 1], 'days since 2000-01-01',
231+
['NaT', '2000-01-01T00:00:00Z', '2000-01-02T00:00:00Z']),
232+
]:
233233
with warnings.catch_warnings():
234234
warnings.filterwarnings('ignore', 'All-NaN')
235235
actual = coding.times.decode_cf_datetime(num_dates, units)

xarray/tests/test_dataarray.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -2930,13 +2930,14 @@ def test_to_and_from_iris_dask(self):
29302930
coord_dict['distance2'] = ('distance', [0, 1], {'foo': 'bar'})
29312931
coord_dict['time2'] = (('distance', 'time'), [[0, 1, 2], [2, 3, 4]])
29322932

2933-
original = DataArray(da.from_array(
2934-
np.arange(-1, 5, dtype='float').reshape(2, 3), 3), coord_dict,
2935-
name='Temperature',
2936-
attrs={'baz': 123, 'units': 'Kelvin',
2937-
'standard_name': 'fire_temperature',
2938-
'long_name': 'Fire Temperature'},
2939-
dims=('distance', 'time'))
2933+
original = DataArray(
2934+
da.from_array(np.arange(-1, 5, dtype='float').reshape(2, 3), 3),
2935+
coord_dict,
2936+
name='Temperature',
2937+
attrs=dict(baz=123, units='Kelvin',
2938+
standard_name='fire_temperature',
2939+
long_name='Fire Temperature'),
2940+
dims=('distance', 'time'))
29402941

29412942
# Set a bad value to test the masking logic
29422943
original.data = da.ma.masked_less(original.data, 0)
@@ -3257,10 +3258,10 @@ def test_rank(self):
32573258
self.assertDataArrayEqual(ar.rank('dim_0'), expect_0)
32583259
self.assertDataArrayEqual(ar.rank('dim_1'), expect_1)
32593260
# int
3260-
x = DataArray([3,2,1])
3261+
x = DataArray([3, 2, 1])
32613262
self.assertDataArrayEqual(x.rank('dim_0'), x)
32623263
# str
3263-
y = DataArray(['c', 'b', 'a'])
3264+
y = DataArray(['c', 'b', 'a'])
32643265
self.assertDataArrayEqual(y.rank('dim_0'), x)
32653266

32663267
x = DataArray([3.0, 1.0, np.nan, 2.0, 4.0], dims=('z',))

xarray/tests/test_plot.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ def test_2d_line_accepts_legend_kw(self):
110110
self.darray[:, :, 0].plot.line(x='dim_0', add_legend=True)
111111
self.assertTrue(plt.gca().get_legend())
112112
# check whether legend title is set
113-
self.assertTrue(plt.gca().get_legend().get_title().get_text()
114-
== 'dim_1')
113+
self.assertEqual(plt.gca().get_legend().get_title().get_text(),
114+
'dim_1')
115115

116116
def test_2d_line_accepts_x_kw(self):
117117
self.darray[:, :, 0].plot.line(x='dim_0')
@@ -122,12 +122,12 @@ def test_2d_line_accepts_x_kw(self):
122122

123123
def test_2d_line_accepts_hue_kw(self):
124124
self.darray[:, :, 0].plot.line(hue='dim_0')
125-
self.assertTrue(plt.gca().get_legend().get_title().get_text()
126-
== 'dim_0')
125+
self.assertEqual(plt.gca().get_legend().get_title().get_text(),
126+
'dim_0')
127127
plt.cla()
128128
self.darray[:, :, 0].plot.line(hue='dim_1')
129-
self.assertTrue(plt.gca().get_legend().get_title().get_text()
130-
== 'dim_1')
129+
self.assertEqual(plt.gca().get_legend().get_title().get_text(),
130+
'dim_1')
131131

132132
def test_2d_before_squeeze(self):
133133
a = DataArray(easy_array((1, 5)))

xarray/tests/test_variable.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1404,7 +1404,7 @@ def test_rank(self):
14041404
expect = bn.rankdata(v.data, axis=0)
14051405
np.testing.assert_allclose(v.rank('x').values, expect)
14061406
# str
1407-
v = Variable(['x'], ['c', 'b', 'a'])
1407+
v = Variable(['x'], ['c', 'b', 'a'])
14081408
expect = bn.rankdata(v.data, axis=0)
14091409
np.testing.assert_allclose(v.rank('x').values, expect)
14101410
# pct

xarray/util/print_versions.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def get_sys_info():
2525
stdout=subprocess.PIPE,
2626
stderr=subprocess.PIPE)
2727
so, serr = pipe.communicate()
28-
except:
28+
except Exception:
2929
pass
3030
else:
3131
if pipe.returncode == 0:
@@ -55,7 +55,7 @@ def get_sys_info():
5555
("LOCALE", "%s.%s" % locale.getlocale()),
5656

5757
])
58-
except:
58+
except Exception:
5959
pass
6060

6161
return blob
@@ -102,13 +102,13 @@ def show_versions(as_json=False):
102102
mod = importlib.import_module(modname)
103103
ver = ver_f(mod)
104104
deps_blob.append((modname, ver))
105-
except:
105+
except Exception:
106106
deps_blob.append((modname, None))
107107

108108
if (as_json):
109109
try:
110110
import json
111-
except:
111+
except Exception:
112112
import simplejson as json
113113

114114
j = dict(system=dict(sys_info), dependencies=dict(deps_blob))

0 commit comments

Comments
 (0)