Skip to content

Commit 08deb10

Browse files
authored
Avoid unnecessary values_from_object (#32398)
1 parent 712fd01 commit 08deb10

File tree

5 files changed

+4
-10
lines changed

5 files changed

+4
-10
lines changed

pandas/_libs/lib.pyx

+1-3
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,9 @@ def values_from_object(obj: object):
100100
"""
101101
func: object
102102

103-
if getattr(obj, '_typ', '') == 'dataframe':
104-
return obj.values
105-
106103
func = getattr(obj, '_internal_get_values', None)
107104
if func is not None:
105+
# Includes DataFrame, for which we get frame.values
108106
obj = func()
109107

110108
return obj

pandas/core/common.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def is_bool_indexer(key: Any) -> bool:
122122
is_array_like(key) and is_extension_array_dtype(key.dtype)
123123
):
124124
if key.dtype == np.object_:
125-
key = np.asarray(values_from_object(key))
125+
key = np.asarray(key)
126126

127127
if not lib.is_bool_array(key):
128128
na_msg = "Cannot mask with non-boolean array containing NA / NaN values"

pandas/core/dtypes/missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ def remove_na_arraylike(arr):
581581
if is_extension_array_dtype(arr):
582582
return arr[notna(arr)]
583583
else:
584-
return arr[notna(lib.values_from_object(arr))]
584+
return arr[notna(np.asarray(arr))]
585585

586586

587587
def is_valid_nat_for_dtype(obj, dtype: DtypeObj) -> bool:

pandas/core/reshape/merge.py

-3
Original file line numberDiff line numberDiff line change
@@ -1923,9 +1923,6 @@ def _factorize_keys(lk, rk, sort=True):
19231923

19241924

19251925
def _sort_labels(uniques: np.ndarray, left, right):
1926-
if not isinstance(uniques, np.ndarray):
1927-
# tuplesafe
1928-
uniques = Index(uniques).values
19291926

19301927
llength = len(left)
19311928
labels = np.concatenate([left, right])

pandas/core/strings.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
from pandas.core.algorithms import take_1d
3838
from pandas.core.base import NoNewAttributesMixin
39-
import pandas.core.common as com
4039
from pandas.core.construction import extract_array
4140

4241
if TYPE_CHECKING:
@@ -782,7 +781,7 @@ def rep(x, r):
782781
return str.__mul__(x, r)
783782

784783
repeats = np.asarray(repeats, dtype=object)
785-
result = libops.vec_binop(com.values_from_object(arr), repeats, rep)
784+
result = libops.vec_binop(np.asarray(arr), repeats, rep)
786785
return result
787786

788787

0 commit comments

Comments
 (0)