9
9
10
10
import xarray as xr
11
11
from xarray .core .indexes import (
12
+ Hashable ,
12
13
Index ,
13
14
Indexes ,
14
15
PandasIndex ,
@@ -535,18 +536,37 @@ def test_copy(self) -> None:
535
536
536
537
class TestIndexes :
537
538
@pytest .fixture
538
- def unique_indexes (self ) -> list [PandasIndex ]:
539
+ def indexes_and_vars (self ) -> tuple [ list [PandasIndex ], dict [ Hashable , Variable ] ]:
539
540
x_idx = PandasIndex (pd .Index ([1 , 2 , 3 ], name = "x" ), "x" )
540
541
y_idx = PandasIndex (pd .Index ([4 , 5 , 6 ], name = "y" ), "y" )
541
542
z_pd_midx = pd .MultiIndex .from_product (
542
543
[["a" , "b" ], [1 , 2 ]], names = ["one" , "two" ]
543
544
)
544
545
z_midx = PandasMultiIndex (z_pd_midx , "z" )
545
546
546
- return [x_idx , y_idx , z_midx ]
547
+ indexes = [x_idx , y_idx , z_midx ]
548
+
549
+ variables = {}
550
+ for idx in indexes :
551
+ variables .update (idx .create_variables ())
552
+
553
+ return indexes , variables
554
+
555
+ @pytest .fixture (params = ["pd_index" , "xr_index" ])
556
+ def unique_indexes (
557
+ self , request , indexes_and_vars
558
+ ) -> list [PandasIndex ] | list [pd .Index ]:
559
+ xr_indexes , _ = indexes_and_vars
560
+
561
+ if request .param == "pd_index" :
562
+ return [idx .index for idx in xr_indexes ]
563
+ else :
564
+ return xr_indexes
547
565
548
566
@pytest .fixture
549
- def indexes (self , unique_indexes ) -> Indexes [Index ]:
567
+ def indexes (
568
+ self , unique_indexes , indexes_and_vars
569
+ ) -> Indexes [Index ] | Indexes [pd .Index ]:
550
570
x_idx , y_idx , z_midx = unique_indexes
551
571
indexes : dict [Any , Index ] = {
552
572
"x" : x_idx ,
@@ -555,9 +575,8 @@ def indexes(self, unique_indexes) -> Indexes[Index]:
555
575
"one" : z_midx ,
556
576
"two" : z_midx ,
557
577
}
558
- variables : dict [Any , Variable ] = {}
559
- for idx in unique_indexes :
560
- variables .update (idx .create_variables ())
578
+
579
+ _ , variables = indexes_and_vars
561
580
562
581
return Indexes (indexes , variables )
563
582
0 commit comments