@@ -59,7 +59,7 @@ def check_reduce_dims(reduce_dims, dimensions):
59
59
60
60
def unique_value_groups (
61
61
ar , sort : bool = True
62
- ) -> tuple [np .ndarray | pd .Index , list [list [int ]]]:
62
+ ) -> tuple [np .ndarray | pd .Index , list [list [int ]], np . ndarray ]:
63
63
"""Group an array by its unique values.
64
64
65
65
Parameters
@@ -706,6 +706,7 @@ def _flox_reduce(
706
706
from xarray .core .dataset import Dataset
707
707
708
708
obj = self ._original_obj
709
+ group = self ._original_group
709
710
710
711
if keep_attrs is None :
711
712
keep_attrs = _get_keep_attrs (default = True )
@@ -735,32 +736,23 @@ def _flox_reduce(
735
736
if index .is_unique and self ._squeeze :
736
737
raise ValueError (f"cannot reduce over dimensions { self ._group .name !r} " )
737
738
738
- if isinstance (self ._original_group , _DummyGroup ):
739
- group = self ._original_group .name
740
- else :
741
- group = self ._original_group
742
-
743
- unindexed_dims : tuple [str , ...] = tuple ()
744
- if isinstance (group , str ):
745
- if group in obj .dims and group not in obj ._indexes and self ._bins is None :
746
- unindexed_dims = (group ,)
747
- group = self ._original_obj [group ]
739
+ unindexed_dims : tuple [Hashable , ...] = tuple ()
740
+ if isinstance (group , _DummyGroup ) and self ._bins is None :
741
+ unindexed_dims = (group .name ,)
748
742
749
743
parsed_dim : tuple [Hashable , ...]
750
744
if isinstance (dim , str ):
751
745
parsed_dim = (dim ,)
752
746
elif dim is None :
753
747
parsed_dim = group .dims
754
748
elif dim is ...:
755
- parsed_dim = tuple (self . _original_obj .dims )
749
+ parsed_dim = tuple (obj .dims )
756
750
else :
757
751
parsed_dim = tuple (dim )
758
752
759
753
# Do this so we raise the same error message whether flox is present or not.
760
754
# Better to control it here than in flox.
761
- if any (
762
- d not in group .dims and d not in self ._original_obj .dims for d in parsed_dim
763
- ):
755
+ if any (d not in group .dims and d not in obj .dims for d in parsed_dim ):
764
756
raise ValueError (f"cannot reduce over dimensions { dim } ." )
765
757
766
758
if kwargs ["func" ] not in ["all" , "any" , "count" ]:
0 commit comments