@@ -552,9 +552,7 @@ def _flox_reduce(self, dim, **kwargs):
552
552
# TODO: switch to xindexes after we can use is_unique
553
553
index = self ._obj .indexes [self ._group .name ]
554
554
if index .is_unique and self ._squeeze :
555
- raise ValueError (
556
- f"Cannot reduce over absent dimensions { self ._group .name !r} "
557
- )
555
+ raise ValueError (f"cannot reduce over dimensions { self ._group .name !r} " )
558
556
559
557
# TODO: only do this for resample, not general groupers...
560
558
# this creates a label DataArray since resample doesn't do that somehow
@@ -577,6 +575,18 @@ def _flox_reduce(self, dim, **kwargs):
577
575
else :
578
576
group = self ._unstacked_group
579
577
578
+ # Do this so we raise the same error message whether flox is present or not.
579
+ # Better to control it here than in flox.
580
+ if isinstance (group , str ):
581
+ group = self ._original_obj [group ]
582
+ if dim not in (None , Ellipsis ):
583
+ if isinstance (dim , str ):
584
+ dim = (dim ,)
585
+ if any (
586
+ d not in group .dims and d not in self ._original_obj .dims for d in dim
587
+ ):
588
+ raise ValueError (f"cannot reduce over dimensions { dim } ." )
589
+
580
590
# TODO: handle bins=N in dask_groupby
581
591
if self ._bins is not None :
582
592
expected_groups = (self ._bins ,)
0 commit comments