@@ -606,7 +606,7 @@ def test_groupby_repr(obj, dim) -> None:
606
606
N = len (np .unique (obj [dim ]))
607
607
expected = f"<{ obj .__class__ .__name__ } GroupBy"
608
608
expected += f", grouped over 1 grouper(s), { N } groups in total:"
609
- expected += f"\n { dim !r} : { N } groups with labels "
609
+ expected += f"\n { dim !r} : { N } / { N } groups present with labels "
610
610
if dim == "x" :
611
611
expected += "1, 2, 3, 4, 5>"
612
612
elif dim == "y" :
@@ -623,7 +623,7 @@ def test_groupby_repr_datetime(obj) -> None:
623
623
actual = repr (obj .groupby ("t.month" ))
624
624
expected = f"<{ obj .__class__ .__name__ } GroupBy"
625
625
expected += ", grouped over 1 grouper(s), 12 groups in total:\n "
626
- expected += " 'month': 12 groups with labels "
626
+ expected += " 'month': 12/12 groups present with labels "
627
627
expected += "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12>"
628
628
assert actual == expected
629
629
@@ -2953,3 +2953,35 @@ def test_groupby_transpose():
2953
2953
second = data .groupby ("x" ).sum ()
2954
2954
2955
2955
assert_identical (first , second .transpose (* first .dims ))
2956
+
2957
+
2958
+ def test_groupby_multiple_bin_grouper_missing_groups ():
2959
+ from numpy import nan
2960
+
2961
+ ds = xr .Dataset (
2962
+ {"foo" : (("z" ), np .arange (12 ))},
2963
+ coords = {"x" : ("z" , np .arange (12 )), "y" : ("z" , np .arange (12 ))},
2964
+ )
2965
+
2966
+ actual = ds .groupby (
2967
+ x = BinGrouper (np .arange (0 , 13 , 4 )), y = BinGrouper (bins = np .arange (0 , 16 , 2 ))
2968
+ ).count ()
2969
+ expected = Dataset (
2970
+ {
2971
+ "foo" : (
2972
+ ("x_bins" , "y_bins" ),
2973
+ np .array (
2974
+ [
2975
+ [2.0 , 2.0 , nan , nan , nan , nan , nan ],
2976
+ [nan , nan , 2.0 , 2.0 , nan , nan , nan ],
2977
+ [nan , nan , nan , nan , 2.0 , 1.0 , nan ],
2978
+ ]
2979
+ ),
2980
+ )
2981
+ },
2982
+ coords = {
2983
+ "x_bins" : ("x_bins" , pd .IntervalIndex .from_breaks (np .arange (0 , 13 , 4 ))),
2984
+ "y_bins" : ("y_bins" , pd .IntervalIndex .from_breaks (np .arange (0 , 16 , 2 ))),
2985
+ },
2986
+ )
2987
+ assert_identical (actual , expected )
0 commit comments