@@ -608,7 +608,7 @@ def assign_coords(self, coords=None, **coords_kwargs):
608
608
Dataset.swap_dims
609
609
"""
610
610
coords_kwargs = either_dict_or_kwargs (coords , coords_kwargs , "assign_coords" )
611
- return self .apply (lambda ds : ds .assign_coords (** coords_kwargs ))
611
+ return self .map (lambda ds : ds .assign_coords (** coords_kwargs ))
612
612
613
613
614
614
def _maybe_reorder (xarray_obj , dim , positions ):
@@ -655,8 +655,8 @@ def lookup_order(dimension):
655
655
new_order = sorted (stacked .dims , key = lookup_order )
656
656
return stacked .transpose (* new_order , transpose_coords = self ._restore_coord_dims )
657
657
658
- def apply (self , func , shortcut = False , args = (), ** kwargs ):
659
- """Apply a function over each array in the group and concatenate them
658
+ def map (self , func , shortcut = False , args = (), ** kwargs ):
659
+ """Apply a function to each array in the group and concatenate them
660
660
together into a new array.
661
661
662
662
`func` is called like `func(ar, *args, **kwargs)` for each array `ar`
@@ -702,6 +702,21 @@ def apply(self, func, shortcut=False, args=(), **kwargs):
702
702
applied = (maybe_wrap_array (arr , func (arr , * args , ** kwargs )) for arr in grouped )
703
703
return self ._combine (applied , shortcut = shortcut )
704
704
705
+ def apply (self , func , shortcut = False , args = (), ** kwargs ):
706
+ """
707
+ Backward compatible implementation of ``map``
708
+
709
+ See Also
710
+ --------
711
+ DataArrayGroupBy.map
712
+ """
713
+ warnings .warn (
714
+ "GroupBy.apply may be deprecated in the future. Using GroupBy.map is encouraged" ,
715
+ PendingDeprecationWarning ,
716
+ stacklevel = 2 ,
717
+ )
718
+ return self .map (func , shortcut = shortcut , args = args , ** kwargs )
719
+
705
720
def _combine (self , applied , restore_coord_dims = False , shortcut = False ):
706
721
"""Recombine the applied objects like the original."""
707
722
applied_example , applied = peek_at (applied )
@@ -765,7 +780,7 @@ def quantile(self, q, dim=None, interpolation="linear", keep_attrs=None):
765
780
if dim is None :
766
781
dim = self ._group_dim
767
782
768
- out = self .apply (
783
+ out = self .map (
769
784
self ._obj .__class__ .quantile ,
770
785
shortcut = False ,
771
786
q = q ,
@@ -820,16 +835,16 @@ def reduce_array(ar):
820
835
821
836
check_reduce_dims (dim , self .dims )
822
837
823
- return self .apply (reduce_array , shortcut = shortcut )
838
+ return self .map (reduce_array , shortcut = shortcut )
824
839
825
840
826
841
ops .inject_reduce_methods (DataArrayGroupBy )
827
842
ops .inject_binary_ops (DataArrayGroupBy )
828
843
829
844
830
845
class DatasetGroupBy (GroupBy , ImplementsDatasetReduce ):
831
- def apply (self , func , args = (), shortcut = None , ** kwargs ):
832
- """Apply a function over each Dataset in the group and concatenate them
846
+ def map (self , func , args = (), shortcut = None , ** kwargs ):
847
+ """Apply a function to each Dataset in the group and concatenate them
833
848
together into a new Dataset.
834
849
835
850
`func` is called like `func(ds, *args, **kwargs)` for each dataset `ds`
@@ -862,6 +877,22 @@ def apply(self, func, args=(), shortcut=None, **kwargs):
862
877
applied = (func (ds , * args , ** kwargs ) for ds in self ._iter_grouped ())
863
878
return self ._combine (applied )
864
879
880
+ def apply (self , func , args = (), shortcut = None , ** kwargs ):
881
+ """
882
+ Backward compatible implementation of ``map``
883
+
884
+ See Also
885
+ --------
886
+ DatasetGroupBy.map
887
+ """
888
+
889
+ warnings .warn (
890
+ "GroupBy.apply may be deprecated in the future. Using GroupBy.map is encouraged" ,
891
+ PendingDeprecationWarning ,
892
+ stacklevel = 2 ,
893
+ )
894
+ return self .map (func , shortcut = shortcut , args = args , ** kwargs )
895
+
865
896
def _combine (self , applied ):
866
897
"""Recombine the applied objects like the original."""
867
898
applied_example , applied = peek_at (applied )
@@ -914,7 +945,7 @@ def reduce_dataset(ds):
914
945
915
946
check_reduce_dims (dim , self .dims )
916
947
917
- return self .apply (reduce_dataset )
948
+ return self .map (reduce_dataset )
918
949
919
950
def assign (self , ** kwargs ):
920
951
"""Assign data variables by group.
@@ -923,7 +954,7 @@ def assign(self, **kwargs):
923
954
--------
924
955
Dataset.assign
925
956
"""
926
- return self .apply (lambda ds : ds .assign (** kwargs ))
957
+ return self .map (lambda ds : ds .assign (** kwargs ))
927
958
928
959
929
960
ops .inject_reduce_methods (DatasetGroupBy )
0 commit comments