@@ -164,27 +164,26 @@ def apply(self, f, data: FrameOrSeries, axis: int = 0):
164
164
com .get_callable_name (f ) not in base .plotting_methods
165
165
and isinstance (splitter , FrameSplitter )
166
166
and axis == 0
167
- # with MultiIndex, apply_frame_axis0 would raise InvalidApply
168
- # TODO: can we make this check prettier?
169
- and not sdata .index ._has_complex_internals
167
+ # apply_frame_axis0 doesn't allow MultiIndex
168
+ and not isinstance (sdata .index , MultiIndex )
170
169
):
171
170
try :
172
171
result_values , mutated = splitter .fast_apply (f , group_keys )
173
172
174
- # If the fast apply path could be used we can return here.
175
- # Otherwise we need to fall back to the slow implementation.
176
- if len (result_values ) == len (group_keys ):
177
- return group_keys , result_values , mutated
178
-
179
173
except libreduction .InvalidApply as err :
180
- # Cannot fast apply on MultiIndex (_has_complex_internals).
181
- # This Exception is also raised if `f` triggers an exception
174
+ # This Exception is raised if `f` triggers an exception
182
175
# but it is preferable to raise the exception in Python.
183
176
if "Let this error raise above us" not in str (err ):
184
177
# TODO: can we infer anything about whether this is
185
178
# worth-retrying in pure-python?
186
179
raise
187
180
181
+ else :
182
+ # If the fast apply path could be used we can return here.
183
+ # Otherwise we need to fall back to the slow implementation.
184
+ if len (result_values ) == len (group_keys ):
185
+ return group_keys , result_values , mutated
186
+
188
187
for key , (i , group ) in zip (group_keys , splitter ):
189
188
object .__setattr__ (group , "name" , key )
190
189
@@ -619,7 +618,7 @@ def agg_series(self, obj: Series, func):
619
618
# TODO: is the datetime64tz case supposed to go through here?
620
619
return self ._aggregate_series_pure_python (obj , func )
621
620
622
- elif obj .index . _has_complex_internals :
621
+ elif isinstance ( obj .index , MultiIndex ) :
623
622
# MultiIndex; Pre-empt TypeError in _aggregate_series_fast
624
623
return self ._aggregate_series_pure_python (obj , func )
625
624
0 commit comments