@@ -164,27 +164,26 @@ def apply(self, f, data: FrameOrSeries, axis: int = 0):
164164 com .get_callable_name (f ) not in base .plotting_methods
165165 and isinstance (splitter , FrameSplitter )
166166 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 )
170169 ):
171170 try :
172171 result_values , mutated = splitter .fast_apply (f , group_keys )
173172
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-
179173 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
182175 # but it is preferable to raise the exception in Python.
183176 if "Let this error raise above us" not in str (err ):
184177 # TODO: can we infer anything about whether this is
185178 # worth-retrying in pure-python?
186179 raise
187180
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+
188187 for key , (i , group ) in zip (group_keys , splitter ):
189188 object .__setattr__ (group , "name" , key )
190189
@@ -619,7 +618,7 @@ def agg_series(self, obj: Series, func):
619618 # TODO: is the datetime64tz case supposed to go through here?
620619 return self ._aggregate_series_pure_python (obj , func )
621620
622- elif obj .index . _has_complex_internals :
621+ elif isinstance ( obj .index , MultiIndex ) :
623622 # MultiIndex; Pre-empt TypeError in _aggregate_series_fast
624623 return self ._aggregate_series_pure_python (obj , func )
625624
0 commit comments