@@ -6,6 +6,7 @@ class providing the base-class of operations.
66(defined in pandas.core.groupby.generic)
77expose these user-facing objects to provide specific functionality.
88"""
9+ from pandas .core .dtypes .generic import ABCDataFrame , ABCIndexClass , ABCSeries
910
1011from contextlib import contextmanager
1112import datetime
@@ -408,7 +409,6 @@ def __init__(
408409 observed = observed ,
409410 mutated = self .mutated ,
410411 )
411-
412412 self .obj = obj
413413 self .axis = obj ._get_axis_number (axis )
414414 self .grouper = grouper
@@ -508,13 +508,17 @@ def _get_index(self, name):
508508 @cache_readonly
509509 def _selected_obj (self ):
510510 # Note: _selected_obj is always just `self.obj` for SeriesGroupBy
511-
512- if self ._selection is None or isinstance (self .obj , Series ):
511+ breakpoint ()
512+ if self .as_index :
513+ obj = self ._obj_with_exclusions
514+ else :
515+ obj = self .obj
516+ if self ._selection is None or isinstance (obj , Series ):
513517 if self ._group_selection is not None :
514- return self . obj [self ._group_selection ]
515- return self . obj
518+ return obj [self ._group_selection ]
519+ return obj
516520 else :
517- return self . obj [self ._selection ]
521+ return obj [self ._selection ]
518522
519523 def _reset_group_selection (self ):
520524 """
@@ -704,7 +708,7 @@ def __iter__(self):
704708 )
705709 )
706710 def apply (self , func , * args , ** kwargs ):
707- # breakpoint()
711+
708712 func = self ._is_builtin_func (func )
709713
710714 # this is needed so we don't try and wrap strings. If we could
@@ -732,7 +736,6 @@ def f(g):
732736 # ignore SettingWithCopy here in case the user mutates
733737 with option_context ("mode.chained_assignment" , None ):
734738 try :
735- # breakpoint()
736739 result = self ._python_apply_general (f )
737740 except TypeError :
738741 # gh-20949
@@ -749,11 +752,7 @@ def f(g):
749752 return result
750753
751754 def _python_apply_general (self , f ):
752- breakpoint ()
753- if self .group_keys :
754- keys , values , mutated = self .grouper .apply (f , self ._obj_with_exclusions , self .axis )
755- else :
756- keys , values , mutated = self .grouper .apply (f , self ._selected_obj , self .axis )
755+ keys , values , mutated = self .grouper .apply (f , self ._selected_obj , self .axis )
757756
758757 return self ._wrap_applied_output (
759758 keys , values , not_indexed_same = mutated or self .mutated
@@ -1581,7 +1580,7 @@ def rolling(self, *args, **kwargs):
15811580 Return a rolling grouper, providing rolling functionality per group.
15821581 """
15831582 from pandas .core .window import RollingGroupby
1584- kwargs [ 'exclusions' ] = self . exclusions
1583+
15851584 return RollingGroupby (self , * args , ** kwargs )
15861585
15871586 @Substitution (name = "groupby" )
0 commit comments