4
4
import numpy as np
5
5
import pandas as pd
6
6
import pickle
7
+ import pytest
7
8
from copy import deepcopy
8
9
from textwrap import dedent
9
10
@@ -263,8 +264,9 @@ def test_constructor_invalid(self):
263
264
with self .assertRaisesRegexp (ValueError , 'conflicting MultiIndex' ):
264
265
DataArray (np .random .rand (4 , 4 ),
265
266
[('x' , self .mindex ), ('y' , self .mindex )])
267
+ with self .assertRaisesRegexp (ValueError , 'conflicting MultiIndex' ):
266
268
DataArray (np .random .rand (4 , 4 ),
267
- [('x' , mindex ), ('level_1' , range (4 ))])
269
+ [('x' , self . mindex ), ('level_1' , range (4 ))])
268
270
269
271
def test_constructor_from_self_described (self ):
270
272
data = [[- 0.1 , 21 ], [0 , 2 ]]
@@ -879,7 +881,6 @@ def test_math_automatic_alignment(self):
879
881
def test_non_overlapping_dataarrays_return_empty_result (self ):
880
882
881
883
a = DataArray (range (5 ), [('x' , range (5 ))])
882
- b = DataArray (range (5 ), [('x' , range (1 , 6 ))])
883
884
result = a .isel (x = slice (2 )) + a .isel (x = slice (2 , None ))
884
885
self .assertEqual (len (result ['x' ]), 0 )
885
886
@@ -889,7 +890,6 @@ def test_empty_dataarrays_return_empty_result(self):
889
890
result = a * a
890
891
self .assertEqual (len (result ['dim_0' ]), 0 )
891
892
892
-
893
893
def test_inplace_math_basics (self ):
894
894
x = self .x
895
895
a = self .dv
@@ -1414,10 +1414,13 @@ def test_groupby_first_and_last(self):
1414
1414
self .assertDataArrayIdentical (expected , actual )
1415
1415
1416
1416
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' ])
1421
1424
1422
1425
def test_groupby_multidim (self ):
1423
1426
array = self .make_groupby_multidim_example_array ()
@@ -2067,10 +2070,7 @@ def test_to_masked_array(self):
2067
2070
self .assertEqual (len (ma .mask ), N )
2068
2071
2069
2072
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' )
2074
2074
2075
2075
original = DataArray (np .arange (6 ).reshape (2 , 3 ),
2076
2076
[('distance' , [- 2 , 2 ], {'units' : 'meters' }),
@@ -2182,6 +2182,7 @@ def test_coordinate_diff(self):
2182
2182
expected = DataArray ([1 ] * 9 , dims = ['lon' ], coords = [range (1 , 10 )],
2183
2183
name = 'lon' )
2184
2184
actual = lon .diff ('lon' )
2185
+ self .assertDataArrayEqual (expected , actual )
2185
2186
2186
2187
def test_shift (self ):
2187
2188
arr = DataArray ([1 , 2 , 3 ], dims = 'x' )
0 commit comments