69
69
requires_sparse ,
70
70
source_ndarray ,
71
71
)
72
+ from xarray .tests .indexes import MultiCoordIndex , ScalarIndex , XYIndex
72
73
73
74
try :
74
75
from pandas .errors import UndefinedVariableError
@@ -1599,30 +1600,6 @@ def test_isel_multicoord_index(self) -> None:
1599
1600
# regression test https://github.com/pydata/xarray/issues/10063
1600
1601
# isel on a multi-coordinate index should return a unique index associated
1601
1602
# to each coordinate
1602
- class MultiCoordIndex (xr .Index ):
1603
- def __init__ (self , idx1 , idx2 ):
1604
- self .idx1 = idx1
1605
- self .idx2 = idx2
1606
-
1607
- @classmethod
1608
- def from_variables (cls , variables , * , options = None ):
1609
- idx1 = PandasIndex .from_variables (
1610
- {"x" : variables ["x" ]}, options = options
1611
- )
1612
- idx2 = PandasIndex .from_variables (
1613
- {"y" : variables ["y" ]}, options = options
1614
- )
1615
-
1616
- return cls (idx1 , idx2 )
1617
-
1618
- def create_variables (self , variables = None ):
1619
- return {** self .idx1 .create_variables (), ** self .idx2 .create_variables ()}
1620
-
1621
- def isel (self , indexers ):
1622
- idx1 = self .idx1 .isel ({"x" : indexers .get ("x" , slice (None ))})
1623
- idx2 = self .idx2 .isel ({"y" : indexers .get ("y" , slice (None ))})
1624
- return MultiCoordIndex (idx1 , idx2 )
1625
-
1626
1603
coords = xr .Coordinates (coords = {"x" : [0 , 1 ], "y" : [1 , 2 ]}, indexes = {})
1627
1604
ds = xr .Dataset (coords = coords ).set_xindex (["x" , "y" ], MultiCoordIndex )
1628
1605
@@ -2639,18 +2616,6 @@ def test_align_index_var_attrs(self, join) -> None:
2639
2616
def test_align_scalar_index (self ) -> None :
2640
2617
# ensure that indexes associated with scalar coordinates are not ignored
2641
2618
# during alignment
2642
- class ScalarIndex (Index ):
2643
- def __init__ (self , value : int ):
2644
- self .value = value
2645
-
2646
- @classmethod
2647
- def from_variables (cls , variables , * , options ):
2648
- var = next (iter (variables .values ()))
2649
- return cls (int (var .values ))
2650
-
2651
- def equals (self , other , * , exclude = None ):
2652
- return isinstance (other , ScalarIndex ) and other .value == self .value
2653
-
2654
2619
ds1 = Dataset (coords = {"x" : 0 }).set_xindex ("x" , ScalarIndex )
2655
2620
ds2 = Dataset (coords = {"x" : 0 }).set_xindex ("x" , ScalarIndex )
2656
2621
@@ -2664,27 +2629,6 @@ def equals(self, other, *, exclude=None):
2664
2629
xr .align (ds1 , ds3 , join = "exact" )
2665
2630
2666
2631
def test_align_multi_dim_index_exclude_dims (self ) -> None :
2667
- class XYIndex (Index ):
2668
- def __init__ (self , x : PandasIndex , y : PandasIndex ):
2669
- self .x : PandasIndex = x
2670
- self .y : PandasIndex = y
2671
-
2672
- @classmethod
2673
- def from_variables (cls , variables , * , options ):
2674
- return cls (
2675
- x = PandasIndex .from_variables (
2676
- {"x" : variables ["x" ]}, options = options
2677
- ),
2678
- y = PandasIndex .from_variables (
2679
- {"y" : variables ["y" ]}, options = options
2680
- ),
2681
- )
2682
-
2683
- def equals (self , other , exclude = None ):
2684
- x_eq = True if self .x .dim in exclude else self .x .equals (other .x )
2685
- y_eq = True if self .y .dim in exclude else self .y .equals (other .y )
2686
- return x_eq and y_eq
2687
-
2688
2632
ds1 = (
2689
2633
Dataset (coords = {"x" : [1 , 2 ], "y" : [3 , 4 ]})
2690
2634
.drop_indexes (["x" , "y" ])
0 commit comments