Skip to content

Commit 0559c6a

Browse files
committed
Replace _has_coplex_internals #29227
1 parent 953757a commit 0559c6a

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
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,
@@ -522,7 +524,7 @@ def apply_frame_axis0(object frame, object f, object names,
522524
object piece
523525
dict item_cache
524526

525-
if frame.index._has_complex_internals:
527+
if isinstance(frame.index, ABCMultiIndex):
526528
raise InvalidApply('Cannot modify frame index internals')
527529

528530
results = []
@@ -653,7 +655,7 @@ def compute_reduction(arr, f, axis=0, dummy=None, labels=None):
653655

654656
if labels is not None:
655657
# Caller is responsible for ensuring we don't have MultiIndex
656-
assert not labels._has_complex_internals
658+
assert not isinstance(frame.index, ABCMultiIndex),('MultiIndex type')
657659

658660
# pass as an ndarray/ExtensionArray
659661
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_type,
@@ -233,7 +235,7 @@ def apply_standard(self):
233235
and not self.dtypes.apply(is_extension_type).any()
234236
# Disallow complex_internals since libreduction shortcut
235237
# cannot handle MultiIndex
236-
and not self.agg_axis._has_complex_internals
238+
and not isinstance(self.agg_axis, ABCMultiIndex)
237239
):
238240

239241
values = self.values

pandas/core/groupby/ops.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import pandas._libs.reduction as libreduction
1616
from pandas.errors import AbstractMethodError
1717
from pandas.util._decorators import cache_readonly
18+
from pandas.core.dtypes.generic import ABCMultiIndex
1819

1920
from pandas.core.dtypes.common import (
2021
ensure_float64,
@@ -201,7 +202,7 @@ def apply(self, f, data, axis=0):
201202
and axis == 0
202203
# with MultiIndex, apply_frame_axis0 would raise InvalidApply
203204
# TODO: can we make this check prettier?
204-
and not splitter._get_sorted_data().index._has_complex_internals
205+
and not isinstance(splitter._get_sorted_data().index, ABCMultiIndex)
205206
):
206207
try:
207208
result_values, mutated = splitter.fast_apply(f, group_keys)
@@ -212,7 +213,7 @@ def apply(self, f, data, axis=0):
212213
return group_keys, result_values, mutated
213214

214215
except libreduction.InvalidApply as err:
215-
# Cannot fast apply on MultiIndex (_has_complex_internals).
216+
# Cannot fast apply on MultiIndex.
216217
# This Exception is also raised if `f` triggers an exception
217218
# but it is preferable to raise the exception in Python.
218219
if "Let this error raise above us" not in str(err):
@@ -698,7 +699,7 @@ def _aggregate_series_fast(self, obj, func):
698699

699700
# TODO: pre-empt this, also pre-empt get_result raising TypError if we pass a EA
700701
# for EAs backed by ndarray we may have a performant workaround
701-
if obj.index._has_complex_internals:
702+
if isinstance(obj.index, ABCMultiIndex)
702703
raise TypeError("Incompatible index for Cython grouper")
703704

704705
group_index, _, ngroups = self.group_info

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
@@ -1394,11 +1394,6 @@ def values(self):
13941394
self._tuples = lib.fast_zip(values)
13951395
return self._tuples
13961396

1397-
@property
1398-
def _has_complex_internals(self):
1399-
# to disable groupby tricks
1400-
return True
1401-
14021397
@cache_readonly
14031398
def is_monotonic_increasing(self):
14041399
"""

0 commit comments

Comments
 (0)