@@ -1042,10 +1042,12 @@ def test_groupby_math_bitshift() -> None:
10421042 assert_equal (right_expected , right_actual )
10431043
10441044
1045+ @pytest .mark .parametrize (
1046+ "x_bins" , ((0 , 2 , 4 , 6 ), pd .IntervalIndex .from_breaks ((0 , 2 , 4 , 6 ), closed = "left" ))
1047+ )
10451048@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 :
10471050 da = xr .DataArray (np .arange (12 ).reshape (6 , 2 ), dims = ("x" , "y" ))
1048- x_bins = (0 , 2 , 4 , 6 )
10491051
10501052 with xr .set_options (use_flox = use_flox ):
10511053 actual = da .groupby_bins (
@@ -1055,7 +1057,12 @@ def test_groupby_bins_cut_kwargs(use_flox: bool) -> None:
10551057 np .array ([[1.0 , 2.0 ], [5.0 , 6.0 ], [9.0 , 10.0 ]]),
10561058 dims = ("x_bins" , "y" ),
10571059 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+ )
10591066 },
10601067 )
10611068 assert_identical (expected , actual )
@@ -1067,9 +1074,8 @@ def test_groupby_bins_cut_kwargs(use_flox: bool) -> None:
10671074 assert_identical (expected , actual )
10681075
10691076 with xr .set_options (use_flox = use_flox ):
1070- bins_index = pd .IntervalIndex .from_breaks (x_bins )
10711077 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 ()
10731079 assert actual .xindexes ["x_bins" ].index .equals (pd .Index (labels )) # type: ignore[attr-defined]
10741080
10751081
0 commit comments