@@ -14,7 +14,7 @@ class providing the base-class of operations.
14
14
import inspect
15
15
import re
16
16
import types
17
- from typing import FrozenSet , Hashable , Iterable , List , Optional , Tuple , Type , Union
17
+ from typing import FrozenSet , Iterable , List , Optional , Tuple , Type , Union
18
18
19
19
import numpy as np
20
20
@@ -439,7 +439,7 @@ def _get_indices(self, names):
439
439
def get_converter (s ):
440
440
# possibly convert to the actual key types
441
441
# in the indices, could be a Timestamp or a np.datetime64
442
- if isinstance (s , ( Timestamp , datetime .datetime ) ):
442
+ if isinstance (s , datetime .datetime ):
443
443
return lambda key : Timestamp (key )
444
444
elif isinstance (s , np .datetime64 ):
445
445
return lambda key : Timestamp (key ).asm8
@@ -488,6 +488,7 @@ def _get_index(self, name):
488
488
489
489
@cache_readonly
490
490
def _selected_obj (self ):
491
+ # Note: _selected_obj is always just `self.obj` for SeriesGroupBy
491
492
492
493
if self ._selection is None or isinstance (self .obj , Series ):
493
494
if self ._group_selection is not None :
@@ -736,7 +737,7 @@ def _python_apply_general(self, f):
736
737
keys , values , not_indexed_same = mutated or self .mutated
737
738
)
738
739
739
- def _iterate_slices (self ) -> Iterable [Tuple [ Optional [ Hashable ], Series ] ]:
740
+ def _iterate_slices (self ) -> Iterable [Series ]:
740
741
raise AbstractMethodError (self )
741
742
742
743
def transform (self , func , * args , ** kwargs ):
@@ -832,7 +833,8 @@ def _transform_should_cast(self, func_nm: str) -> bool:
832
833
833
834
def _cython_transform (self , how : str , numeric_only : bool = True , ** kwargs ):
834
835
output = collections .OrderedDict () # type: dict
835
- for name , obj in self ._iterate_slices ():
836
+ for obj in self ._iterate_slices ():
837
+ name = obj .name
836
838
is_numeric = is_numeric_dtype (obj .dtype )
837
839
if numeric_only and not is_numeric :
838
840
continue
@@ -864,7 +866,8 @@ def _cython_agg_general(
864
866
self , how : str , alt = None , numeric_only : bool = True , min_count : int = - 1
865
867
):
866
868
output = {}
867
- for name , obj in self ._iterate_slices ():
869
+ for obj in self ._iterate_slices ():
870
+ name = obj .name
868
871
is_numeric = is_numeric_dtype (obj .dtype )
869
872
if numeric_only and not is_numeric :
870
873
continue
@@ -883,7 +886,8 @@ def _python_agg_general(self, func, *args, **kwargs):
883
886
884
887
# iterate through "columns" ex exclusions to populate output dict
885
888
output = {}
886
- for name , obj in self ._iterate_slices ():
889
+ for obj in self ._iterate_slices ():
890
+ name = obj .name
887
891
if self .grouper .ngroups == 0 :
888
892
# agg_series below assumes ngroups > 0
889
893
continue
@@ -2234,7 +2238,8 @@ def _get_cythonized_result(
2234
2238
output = collections .OrderedDict () # type: dict
2235
2239
base_func = getattr (libgroupby , how )
2236
2240
2237
- for name , obj in self ._iterate_slices ():
2241
+ for obj in self ._iterate_slices ():
2242
+ name = obj .name
2238
2243
values = obj ._data ._values
2239
2244
2240
2245
if aggregate :
0 commit comments