Skip to content

CLN: Avoid unnecessary values_from_object #32398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,9 @@ def values_from_object(obj: object):
"""
func: object

if getattr(obj, '_typ', '') == 'dataframe':
return obj.values

func = getattr(obj, '_internal_get_values', None)
if func is not None:
# Includes DataFrame, for which we get frame.values
obj = func()

return obj
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def is_bool_indexer(key: Any) -> bool:
is_array_like(key) and is_extension_array_dtype(key.dtype)
):
if key.dtype == np.object_:
key = np.asarray(values_from_object(key))
key = np.asarray(key)

if not lib.is_bool_array(key):
na_msg = "Cannot mask with non-boolean array containing NA / NaN values"
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ def remove_na_arraylike(arr):
if is_extension_array_dtype(arr):
return arr[notna(arr)]
else:
return arr[notna(lib.values_from_object(arr))]
return arr[notna(np.asarray(arr))]


def is_valid_nat_for_dtype(obj, dtype: DtypeObj) -> bool:
Expand Down
3 changes: 0 additions & 3 deletions pandas/core/reshape/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1923,9 +1923,6 @@ def _factorize_keys(lk, rk, sort=True):


def _sort_labels(uniques: np.ndarray, left, right):
if not isinstance(uniques, np.ndarray):
# tuplesafe
uniques = Index(uniques).values

llength = len(left)
labels = np.concatenate([left, right])
Expand Down
3 changes: 1 addition & 2 deletions pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

from pandas.core.algorithms import take_1d
from pandas.core.base import NoNewAttributesMixin
import pandas.core.common as com
from pandas.core.construction import extract_array

if TYPE_CHECKING:
Expand Down Expand Up @@ -782,7 +781,7 @@ def rep(x, r):
return str.__mul__(x, r)

repeats = np.asarray(repeats, dtype=object)
result = libops.vec_binop(com.values_from_object(arr), repeats, rep)
result = libops.vec_binop(np.asarray(arr), repeats, rep)
return result


Expand Down