Skip to content

Commit 0163b79

Browse files
authored
CLN: avoid getattr(obj, "values", obj) (#33776)
1 parent 8c1df8d commit 0163b79

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

pandas/_libs/hashtable_func_helper.pxi.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ cpdef value_count_{{dtype}}({{c_type}}[:] values, bint dropna):
125125
{{if dtype == 'object'}}
126126
def duplicated_{{dtype}}(ndarray[{{dtype}}] values, object keep='first'):
127127
{{else}}
128-
def duplicated_{{dtype}}({{c_type}}[:] values, object keep='first'):
128+
def duplicated_{{dtype}}(const {{c_type}}[:] values, object keep='first'):
129129
{{endif}}
130130
cdef:
131131
int ret = 0

pandas/core/algorithms.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
ABCExtensionArray,
5050
ABCIndex,
5151
ABCIndexClass,
52+
ABCMultiIndex,
5253
ABCSeries,
5354
)
5455
from pandas.core.dtypes.missing import isna, na_value_for_dtype
@@ -89,6 +90,10 @@ def _ensure_data(values, dtype=None):
8990
values : ndarray
9091
pandas_dtype : str or dtype
9192
"""
93+
if not isinstance(values, ABCMultiIndex):
94+
# extract_array would raise
95+
values = extract_array(values, extract_numpy=True)
96+
9297
# we check some simple dtypes first
9398
if is_object_dtype(dtype):
9499
return ensure_object(np.asarray(values)), "object"
@@ -151,7 +156,6 @@ def _ensure_data(values, dtype=None):
151156
elif is_categorical_dtype(values) and (
152157
is_categorical_dtype(dtype) or dtype is None
153158
):
154-
values = getattr(values, "values", values)
155159
values = values.codes
156160
dtype = "category"
157161

pandas/core/arrays/interval.py

-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,6 @@ def fillna(self, value=None, method=None, limit=None):
648648
)
649649
raise TypeError(msg)
650650

651-
value = getattr(value, "_values", value)
652651
self._check_closed_matches(value, name="value")
653652

654653
left = self.left.fillna(value=value.left)

pandas/core/computation/expressions.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ def _evaluate_numexpr(op, op_str, a, b):
102102
# we were originally called by a reversed op method
103103
a, b = b, a
104104

105-
a_value = getattr(a, "values", a)
106-
b_value = getattr(b, "values", b)
105+
a_value = a
106+
b_value = b
107107

108108
result = ne.evaluate(
109109
f"a_value {op_str} b_value",

pandas/core/window/rolling.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
from pandas.core.base import DataError, PandasObject, SelectionMixin, ShallowMixin
3939
import pandas.core.common as com
40+
from pandas.core.construction import extract_array
4041
from pandas.core.indexes.api import Index, ensure_index
4142
from pandas.core.util.numba_ import NUMBA_FUNC_CACHE
4243
from pandas.core.window.common import (
@@ -252,7 +253,7 @@ def __iter__(self):
252253
def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray:
253254
"""Convert input to numpy arrays for Cython routines"""
254255
if values is None:
255-
values = getattr(self._selected_obj, "values", self._selected_obj)
256+
values = extract_array(self._selected_obj, extract_numpy=True)
256257

257258
# GH #12373 : rolling functions error on float32 data
258259
# make sure the data is coerced to float64

0 commit comments

Comments
 (0)