@@ -486,7 +486,8 @@ def test_loc_single_boolean(self):
486
486
self .assertEqual (data .loc [False ], 1 )
487
487
488
488
def test_multiindex (self ):
489
- idx = pd .MultiIndex .from_product ([list ('abc' ), [0 , 1 ]])
489
+ idx = pd .MultiIndex .from_product ([list ('abc' ), [0 , 1 ]],
490
+ names = ('one' , 'two' ))
490
491
data = DataArray (range (6 ), [('x' , idx )])
491
492
492
493
self .assertDataArrayIdentical (data .sel (x = ('a' , 0 )), data .isel (x = 0 ))
@@ -495,6 +496,20 @@ def test_multiindex(self):
495
496
self .assertDataArrayIdentical (data .sel (x = [('a' , 0 ), ('c' , 1 )]),
496
497
data .isel (x = [0 , - 1 ]))
497
498
self .assertDataArrayIdentical (data .sel (x = 'a' ), data .isel (x = slice (2 )))
499
+ self .assertVariableNotEqual (data .sel (x = {'one' : slice (None )}), data )
500
+ self .assertDataArrayIdentical (data .isel (x = [0 ]),
501
+ data .sel (x = {'one' : 'a' , 'two' : 0 }))
502
+ self .assertDataArrayIdentical (data .isel (x = [0 , 1 ]), data .sel (x = 'a' ))
503
+ self .assertVariableIdentical (
504
+ data .sel (x = {'one' : 'a' }),
505
+ data .unstack ('x' ).sel (one = 'a' ).dropna ('two' )
506
+ )
507
+
508
+ self .assertDataArrayIdentical (data .loc ['a' ], data [:2 ])
509
+ self .assertDataArrayIdentical (data .loc [{'one' : 'a' , 'two' : 0 }, ...],
510
+ data [[0 ]])
511
+ self .assertDataArrayIdentical (data .loc [{'one' : 'a' }, ...],
512
+ data .sel (x = {'one' : 'a' }))
498
513
499
514
def test_time_components (self ):
500
515
dates = pd .date_range ('2000-01-01' , periods = 10 )
@@ -1792,29 +1807,29 @@ def test_full_like(self):
1792
1807
actual = _full_like (DataArray ([1 , 2 , 3 ]), fill_value = np .nan )
1793
1808
self .assertEqual (actual .dtype , np .float )
1794
1809
np .testing .assert_equal (actual .values , np .nan )
1795
-
1810
+
1796
1811
def test_dot (self ):
1797
1812
x = np .linspace (- 3 , 3 , 6 )
1798
1813
y = np .linspace (- 3 , 3 , 5 )
1799
- z = range (4 )
1814
+ z = range (4 )
1800
1815
da_vals = np .arange (6 * 5 * 4 ).reshape ((6 , 5 , 4 ))
1801
1816
da = DataArray (da_vals , coords = [x , y , z ], dims = ['x' , 'y' , 'z' ])
1802
-
1817
+
1803
1818
dm_vals = range (4 )
1804
1819
dm = DataArray (dm_vals , coords = [z ], dims = ['z' ])
1805
-
1820
+
1806
1821
# nd dot 1d
1807
1822
actual = da .dot (dm )
1808
1823
expected_vals = np .tensordot (da_vals , dm_vals , [2 , 0 ])
1809
1824
expected = DataArray (expected_vals , coords = [x , y ], dims = ['x' , 'y' ])
1810
1825
self .assertDataArrayEqual (expected , actual )
1811
-
1826
+
1812
1827
# all shared dims
1813
1828
actual = da .dot (da )
1814
1829
expected_vals = np .tensordot (da_vals , da_vals , axes = ([0 , 1 , 2 ], [0 , 1 , 2 ]))
1815
1830
expected = DataArray (expected_vals )
1816
1831
self .assertDataArrayEqual (expected , actual )
1817
-
1832
+
1818
1833
# multiple shared dims
1819
1834
dm_vals = np .arange (20 * 5 * 4 ).reshape ((20 , 5 , 4 ))
1820
1835
j = np .linspace (- 3 , 3 , 20 )
@@ -1823,7 +1838,7 @@ def test_dot(self):
1823
1838
expected_vals = np .tensordot (da_vals , dm_vals , axes = ([1 , 2 ], [1 , 2 ]))
1824
1839
expected = DataArray (expected_vals , coords = [x , j ], dims = ['x' , 'j' ])
1825
1840
self .assertDataArrayEqual (expected , actual )
1826
-
1841
+
1827
1842
with self .assertRaises (NotImplementedError ):
1828
1843
da .dot (dm .to_dataset (name = 'dm' ))
1829
1844
with self .assertRaises (TypeError ):
0 commit comments