34
34
is_timedelta64_dtype ,
35
35
needs_i8_conversion ,
36
36
)
37
+ from pandas .core .dtypes .generic import ABCMultiIndex
37
38
from pandas .core .dtypes .missing import _maybe_fill , isna
38
39
39
40
import pandas .core .algorithms as algorithms
@@ -160,8 +161,7 @@ def apply(self, f, data, axis: int = 0):
160
161
and hasattr (splitter , "fast_apply" )
161
162
and axis == 0
162
163
# with MultiIndex, apply_frame_axis0 would raise InvalidApply
163
- # TODO: can we make this check prettier?
164
- and not sdata .index ._has_complex_internals
164
+ and not isinstance (sdata .index , ABCMultiIndex )
165
165
):
166
166
try :
167
167
result_values , mutated = splitter .fast_apply (f , group_keys )
@@ -172,7 +172,7 @@ def apply(self, f, data, axis: int = 0):
172
172
return group_keys , result_values , mutated
173
173
174
174
except libreduction .InvalidApply as err :
175
- # Cannot fast apply on MultiIndex (_has_complex_internals) .
175
+ # Cannot fast apply on MultiIndex.
176
176
# This Exception is also raised if `f` triggers an exception
177
177
# but it is preferable to raise the exception in Python.
178
178
if "Let this error raise above us" not in str (err ):
@@ -608,7 +608,7 @@ def agg_series(self, obj: Series, func):
608
608
# TODO: is the datetime64tz case supposed to go through here?
609
609
return self ._aggregate_series_pure_python (obj , func )
610
610
611
- elif obj .index . _has_complex_internals :
611
+ elif isinstance ( obj .index , ABCMultiIndex ) :
612
612
# MultiIndex; Pre-empt TypeError in _aggregate_series_fast
613
613
return self ._aggregate_series_pure_python (obj , func )
614
614
0 commit comments