@@ -1042,10 +1042,12 @@ def test_groupby_math_bitshift() -> None:
1042
1042
assert_equal (right_expected , right_actual )
1043
1043
1044
1044
1045
+ @pytest .mark .parametrize (
1046
+ "x_bins" , ((0 , 2 , 4 , 6 ), pd .IntervalIndex .from_breaks ((0 , 2 , 4 , 6 ), closed = "left" ))
1047
+ )
1045
1048
@pytest .mark .parametrize ("use_flox" , [True , False ])
1046
- def test_groupby_bins_cut_kwargs (use_flox : bool ) -> None :
1049
+ def test_groupby_bins_cut_kwargs (use_flox : bool , x_bins ) -> None :
1047
1050
da = xr .DataArray (np .arange (12 ).reshape (6 , 2 ), dims = ("x" , "y" ))
1048
- x_bins = (0 , 2 , 4 , 6 )
1049
1051
1050
1052
with xr .set_options (use_flox = use_flox ):
1051
1053
actual = da .groupby_bins (
@@ -1055,7 +1057,12 @@ def test_groupby_bins_cut_kwargs(use_flox: bool) -> None:
1055
1057
np .array ([[1.0 , 2.0 ], [5.0 , 6.0 ], [9.0 , 10.0 ]]),
1056
1058
dims = ("x_bins" , "y" ),
1057
1059
coords = {
1058
- "x_bins" : ("x_bins" , pd .IntervalIndex .from_breaks (x_bins , closed = "left" ))
1060
+ "x_bins" : (
1061
+ "x_bins" ,
1062
+ x_bins
1063
+ if isinstance (x_bins , pd .IntervalIndex )
1064
+ else pd .IntervalIndex .from_breaks (x_bins , closed = "left" ),
1065
+ )
1059
1066
},
1060
1067
)
1061
1068
assert_identical (expected , actual )
@@ -1067,9 +1074,8 @@ def test_groupby_bins_cut_kwargs(use_flox: bool) -> None:
1067
1074
assert_identical (expected , actual )
1068
1075
1069
1076
with xr .set_options (use_flox = use_flox ):
1070
- bins_index = pd .IntervalIndex .from_breaks (x_bins )
1071
1077
labels = ["one" , "two" , "three" ]
1072
- actual = da .groupby (x = BinGrouper (bins = bins_index , labels = labels )).sum ()
1078
+ actual = da .groupby (x = BinGrouper (bins = x_bins , labels = labels )).sum ()
1073
1079
assert actual .xindexes ["x_bins" ].index .equals (pd .Index (labels )) # type: ignore[attr-defined]
1074
1080
1075
1081
0 commit comments