Skip to content

CLN: use _values_for_argsort in fewer places #33501

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 3 commits into from
Apr 17, 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
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ def factorize(
values = _ensure_arraylike(values)
original = values

if is_extension_array_dtype(values):
if is_extension_array_dtype(values.dtype):
values = extract_array(values)
codes, uniques = values.factorize(na_sentinel=na_sentinel)
dtype = original.dtype
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def __init__(
# we're inferring from values
dtype = CategoricalDtype(categories, dtype.ordered)

elif is_categorical_dtype(values):
elif is_categorical_dtype(values.dtype):
old_codes = (
values._values.codes if isinstance(values, ABCSeries) else values.codes
)
Expand Down
16 changes: 4 additions & 12 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3597,12 +3597,8 @@ def _join_non_unique(self, other, how="left", return_indexers=False):
# We only get here if dtypes match
assert self.dtype == other.dtype

if is_extension_array_dtype(self.dtype):
lvalues = self._data._values_for_argsort()
rvalues = other._data._values_for_argsort()
else:
lvalues = self._values
rvalues = other._values
lvalues = self._get_engine_target()
rvalues = other._get_engine_target()

left_idx, right_idx = _get_join_indexers(
[lvalues], [rvalues], how=how, sort=True
Expand Down Expand Up @@ -3774,12 +3770,8 @@ def _join_monotonic(self, other, how="left", return_indexers=False):
else:
return ret_index

if is_extension_array_dtype(self.dtype):
sv = self._data._values_for_argsort()
ov = other._data._values_for_argsort()
else:
sv = self._values
ov = other._values
sv = self._get_engine_target()
ov = other._get_engine_target()

if self.is_unique and other.is_unique:
# We can perform much better than the general case
Expand Down
3 changes: 3 additions & 0 deletions pandas/core/indexes/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def __array__(self, dtype=None) -> np.ndarray:
return np.asarray(self._data, dtype=dtype)

def _get_engine_target(self) -> np.ndarray:
# NB: _values_for_argsort happens to match the desired engine targets
# for all of our existing EA-backed indexes, but in general
# cannot be relied upon to exist.
return self._data._values_for_argsort()

@doc(Index.dropna)
Expand Down