@@ -814,6 +814,74 @@ def rolling_exp(
814
814
815
815
return rolling_exp .RollingExp (self , window , window_type )
816
816
817
+ def _groupby (self , groupby_cls , group , squeeze : bool , restore_coord_dims ):
818
+ from xarray .core .groupby import UniqueGrouper , _validate_group
819
+
820
+ # While we don't generally check the type of every arg, passing
821
+ # multiple dimensions as multiple arguments is common enough, and the
822
+ # consequences hidden enough (strings evaluate as true) to warrant
823
+ # checking here.
824
+ # A future version could make squeeze kwarg only, but would face
825
+ # backward-compat issues.
826
+ if not isinstance (squeeze , bool ):
827
+ raise TypeError (
828
+ f"`squeeze` must be True or False, but { squeeze } was supplied"
829
+ )
830
+
831
+ newobj , name = _validate_group (self , group )
832
+
833
+ grouper = UniqueGrouper ()
834
+ return groupby_cls (
835
+ newobj ,
836
+ {name : grouper },
837
+ squeeze = squeeze ,
838
+ restore_coord_dims = restore_coord_dims ,
839
+ )
840
+
841
+ def _groupby_bins (
842
+ self ,
843
+ groupby_cls ,
844
+ group : Hashable | DataArray | IndexVariable ,
845
+ bins : ArrayLike ,
846
+ right : bool = True ,
847
+ labels : ArrayLike | None = None ,
848
+ precision : int = 3 ,
849
+ include_lowest : bool = False ,
850
+ squeeze : bool = True ,
851
+ restore_coord_dims : bool = False ,
852
+ ):
853
+ from xarray .core .groupby import BinGrouper , _validate_group
854
+
855
+ # While we don't generally check the type of every arg, passing
856
+ # multiple dimensions as multiple arguments is common enough, and the
857
+ # consequences hidden enough (strings evaluate as true) to warrant
858
+ # checking here.
859
+ # A future version could make squeeze kwarg only, but would face
860
+ # backward-compat issues.
861
+ if not isinstance (squeeze , bool ):
862
+ raise TypeError (
863
+ f"`squeeze` must be True or False, but { squeeze } was supplied"
864
+ )
865
+
866
+ newobj , name = _validate_group (self , group )
867
+
868
+ grouper = BinGrouper (
869
+ bins = bins ,
870
+ cut_kwargs = {
871
+ "right" : right ,
872
+ "labels" : labels ,
873
+ "precision" : precision ,
874
+ "include_lowest" : include_lowest ,
875
+ },
876
+ )
877
+
878
+ return groupby_cls (
879
+ newobj ,
880
+ {name : grouper },
881
+ squeeze = squeeze ,
882
+ restore_coord_dims = restore_coord_dims ,
883
+ )
884
+
817
885
def _resample (
818
886
self ,
819
887
resample_cls : type [T_Resample ],
@@ -1000,12 +1068,13 @@ def _resample(
1000
1068
if base is not None :
1001
1069
offset = _convert_base_to_offset (base , freq , index )
1002
1070
1071
+ name = RESAMPLE_DIM
1003
1072
group = DataArray (
1004
- dim_coord , coords = dim_coord .coords , dims = dim_coord .dims , name = RESAMPLE_DIM
1073
+ dim_coord , coords = dim_coord .coords , dims = dim_coord .dims , name = name
1005
1074
)
1075
+ newobj = self .copy ().assign_coords ({name : group })
1006
1076
1007
1077
grouper = TimeResampleGrouper (
1008
- group = group ,
1009
1078
freq = freq ,
1010
1079
closed = closed ,
1011
1080
label = label ,
@@ -1015,8 +1084,8 @@ def _resample(
1015
1084
)
1016
1085
1017
1086
return resample_cls (
1018
- self ,
1019
- grouper = grouper ,
1087
+ newobj ,
1088
+ { name : grouper } ,
1020
1089
dim = dim_name ,
1021
1090
resample_dim = RESAMPLE_DIM ,
1022
1091
restore_coord_dims = restore_coord_dims ,
0 commit comments