Skip to content

Commit d01077a

Browse files
MaximilianRshoyer
authored andcommitted
Minor test fixes (#1146)
1 parent cc10cc5 commit d01077a

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pip-log.txt
2626
.coverage
2727
.tox
2828
nosetests.xml
29+
.cache
2930

3031
# Translations
3132
*.mo

xarray/test/test_dataarray.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import numpy as np
55
import pandas as pd
66
import pickle
7+
import pytest
78
from copy import deepcopy
89
from textwrap import dedent
910

@@ -263,8 +264,9 @@ def test_constructor_invalid(self):
263264
with self.assertRaisesRegexp(ValueError, 'conflicting MultiIndex'):
264265
DataArray(np.random.rand(4, 4),
265266
[('x', self.mindex), ('y', self.mindex)])
267+
with self.assertRaisesRegexp(ValueError, 'conflicting MultiIndex'):
266268
DataArray(np.random.rand(4, 4),
267-
[('x', mindex), ('level_1', range(4))])
269+
[('x', self.mindex), ('level_1', range(4))])
268270

269271
def test_constructor_from_self_described(self):
270272
data = [[-0.1, 21], [0, 2]]
@@ -879,7 +881,6 @@ def test_math_automatic_alignment(self):
879881
def test_non_overlapping_dataarrays_return_empty_result(self):
880882

881883
a = DataArray(range(5), [('x', range(5))])
882-
b = DataArray(range(5), [('x', range(1, 6))])
883884
result = a.isel(x=slice(2)) + a.isel(x=slice(2, None))
884885
self.assertEqual(len(result['x']), 0)
885886

@@ -889,7 +890,6 @@ def test_empty_dataarrays_return_empty_result(self):
889890
result = a * a
890891
self.assertEqual(len(result['dim_0']), 0)
891892

892-
893893
def test_inplace_math_basics(self):
894894
x = self.x
895895
a = self.dv
@@ -1414,10 +1414,13 @@ def test_groupby_first_and_last(self):
14141414
self.assertDataArrayIdentical(expected, actual)
14151415

14161416
def make_groupby_multidim_example_array(self):
1417-
return DataArray([[[0,1],[2,3]],[[5,10],[15,20]]],
1418-
coords={'lon': (['ny', 'nx'], [[30., 40.], [40., 50.]] ),
1419-
'lat': (['ny', 'nx'], [[10., 10.], [20., 20.]] ),},
1420-
dims=['time', 'ny', 'nx'])
1417+
return DataArray(
1418+
[[[0, 1], [2, 3]], [[5, 10], [15, 20]]],
1419+
coords={
1420+
'lon': (['ny', 'nx'], [[30., 40.], [40., 50.]]),
1421+
'lat': (['ny', 'nx'], [[10., 10.], [20., 20.]]),
1422+
},
1423+
dims=['time', 'ny', 'nx'])
14211424

14221425
def test_groupby_multidim(self):
14231426
array = self.make_groupby_multidim_example_array()
@@ -2067,10 +2070,7 @@ def test_to_masked_array(self):
20672070
self.assertEqual(len(ma.mask), N)
20682071

20692072
def test_to_and_from_cdms2(self):
2070-
try:
2071-
import cdms2
2072-
except ImportError:
2073-
raise unittest.SkipTest('cdms2 not installed')
2073+
pytest.importorskip('cdms2')
20742074

20752075
original = DataArray(np.arange(6).reshape(2, 3),
20762076
[('distance', [-2, 2], {'units': 'meters'}),
@@ -2182,6 +2182,7 @@ def test_coordinate_diff(self):
21822182
expected = DataArray([1] * 9, dims=['lon'], coords=[range(1, 10)],
21832183
name='lon')
21842184
actual = lon.diff('lon')
2185+
self.assertDataArrayEqual(expected, actual)
21852186

21862187
def test_shift(self):
21872188
arr = DataArray([1, 2, 3], dims='x')

0 commit comments

Comments
 (0)