@@ -6,6 +6,7 @@ class providing the base-class of operations.
6
6
(defined in pandas.core.groupby.generic)
7
7
expose these user-facing objects to provide specific functionality.
8
8
"""
9
+ from pandas .core .dtypes .generic import ABCDataFrame , ABCIndexClass , ABCSeries
9
10
10
11
from contextlib import contextmanager
11
12
import datetime
@@ -408,7 +409,6 @@ def __init__(
408
409
observed = observed ,
409
410
mutated = self .mutated ,
410
411
)
411
-
412
412
self .obj = obj
413
413
self .axis = obj ._get_axis_number (axis )
414
414
self .grouper = grouper
@@ -508,13 +508,17 @@ def _get_index(self, name):
508
508
@cache_readonly
509
509
def _selected_obj (self ):
510
510
# 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 ):
513
517
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
516
520
else :
517
- return self . obj [self ._selection ]
521
+ return obj [self ._selection ]
518
522
519
523
def _reset_group_selection (self ):
520
524
"""
@@ -704,7 +708,7 @@ def __iter__(self):
704
708
)
705
709
)
706
710
def apply (self , func , * args , ** kwargs ):
707
- # breakpoint()
711
+
708
712
func = self ._is_builtin_func (func )
709
713
710
714
# this is needed so we don't try and wrap strings. If we could
@@ -732,7 +736,6 @@ def f(g):
732
736
# ignore SettingWithCopy here in case the user mutates
733
737
with option_context ("mode.chained_assignment" , None ):
734
738
try :
735
- # breakpoint()
736
739
result = self ._python_apply_general (f )
737
740
except TypeError :
738
741
# gh-20949
@@ -749,11 +752,7 @@ def f(g):
749
752
return result
750
753
751
754
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 )
757
756
758
757
return self ._wrap_applied_output (
759
758
keys , values , not_indexed_same = mutated or self .mutated
@@ -1581,7 +1580,7 @@ def rolling(self, *args, **kwargs):
1581
1580
Return a rolling grouper, providing rolling functionality per group.
1582
1581
"""
1583
1582
from pandas .core .window import RollingGroupby
1584
- kwargs [ 'exclusions' ] = self . exclusions
1583
+
1585
1584
return RollingGroupby (self , * args , ** kwargs )
1586
1585
1587
1586
@Substitution (name = "groupby" )
0 commit comments