Skip to content

Commit a3a4c7e

Browse files
Aivengoejbrockmendel
authored andcommitted
Replace _has_coplex_internals #29227
1 parent 8e4424f commit a3a4c7e

File tree

5 files changed

+11
-17
lines changed

5 files changed

+11
-17
lines changed

pandas/_libs/reduction.pyx

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ from cpython.ref cimport Py_INCREF
55

66
from libc.stdlib cimport malloc, free
77

8+
from pandas.core.dtypes.generic import ABCMultiIndex
9+
810
import numpy as np
911
cimport numpy as cnp
1012
from numpy cimport (ndarray,
@@ -492,7 +494,7 @@ def apply_frame_axis0(object frame, object f, object names,
492494
object piece
493495
dict item_cache
494496

495-
if frame.index._has_complex_internals:
497+
if isinstance(frame.index, ABCMultiIndex):
496498
raise InvalidApply('Cannot modify frame index internals')
497499

498500
results = []
@@ -624,7 +626,7 @@ def compute_reduction(arr, f, axis=0, dummy=None, labels=None):
624626

625627
if labels is not None:
626628
# Caller is responsible for ensuring we don't have MultiIndex
627-
assert not labels._has_complex_internals
629+
assert not isinstance(frame.index, ABCMultiIndex),('MultiIndex type')
628630

629631
# pass as an ndarray/ExtensionArray
630632
labels = labels._values

pandas/core/apply.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from pandas._libs import reduction as libreduction
66
from pandas.util._decorators import cache_readonly
77

8+
from pandas.core.dtypes.generic import ABCMultiIndex
9+
810
from pandas.core.dtypes.common import (
911
is_dict_like,
1012
is_extension_array_dtype,
@@ -231,7 +233,7 @@ def apply_standard(self):
231233
and not self.dtypes.apply(is_extension_array_dtype).any()
232234
# Disallow complex_internals since libreduction shortcut
233235
# cannot handle MultiIndex
234-
and not self.agg_axis._has_complex_internals
236+
and not isinstance(self.agg_axis, ABCMultiIndex)
235237
):
236238

237239
values = self.values

pandas/core/groupby/ops.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
is_timedelta64_dtype,
3535
needs_i8_conversion,
3636
)
37+
from pandas.core.dtypes.generic import ABCMultiIndex
3738
from pandas.core.dtypes.missing import _maybe_fill, isna
3839

3940
import pandas.core.algorithms as algorithms
@@ -160,8 +161,7 @@ def apply(self, f, data, axis: int = 0):
160161
and hasattr(splitter, "fast_apply")
161162
and axis == 0
162163
# 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)
165165
):
166166
try:
167167
result_values, mutated = splitter.fast_apply(f, group_keys)
@@ -172,7 +172,7 @@ def apply(self, f, data, axis: int = 0):
172172
return group_keys, result_values, mutated
173173

174174
except libreduction.InvalidApply as err:
175-
# Cannot fast apply on MultiIndex (_has_complex_internals).
175+
# Cannot fast apply on MultiIndex.
176176
# This Exception is also raised if `f` triggers an exception
177177
# but it is preferable to raise the exception in Python.
178178
if "Let this error raise above us" not in str(err):
@@ -608,7 +608,7 @@ def agg_series(self, obj: Series, func):
608608
# TODO: is the datetime64tz case supposed to go through here?
609609
return self._aggregate_series_pure_python(obj, func)
610610

611-
elif obj.index._has_complex_internals:
611+
elif isinstance(obj.index, ABCMultiIndex):
612612
# MultiIndex; Pre-empt TypeError in _aggregate_series_fast
613613
return self._aggregate_series_pure_python(obj, func)
614614

pandas/core/indexes/base.py

-5
Original file line numberDiff line numberDiff line change
@@ -4089,11 +4089,6 @@ def _assert_can_do_op(self, value):
40894089
msg = "'value' must be a scalar, passed: {0}"
40904090
raise TypeError(msg.format(type(value).__name__))
40914091

4092-
@property
4093-
def _has_complex_internals(self):
4094-
# to disable groupby tricks in MultiIndex
4095-
return False
4096-
40974092
def _is_memory_usage_qualified(self):
40984093
"""
40994094
Return a boolean if we need a qualified .info display.

pandas/core/indexes/multi.py

-5
Original file line numberDiff line numberDiff line change
@@ -1396,11 +1396,6 @@ def values(self):
13961396
self._tuples = lib.fast_zip(values)
13971397
return self._tuples
13981398

1399-
@property
1400-
def _has_complex_internals(self):
1401-
# to disable groupby tricks
1402-
return True
1403-
14041399
@cache_readonly
14051400
def is_monotonic_increasing(self):
14061401
"""

0 commit comments

Comments
 (0)