8000 REF: Categorical.is_dtype_equal -> categories_match_up_to_permutation by jbrockmendel · Pull Request #37545 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

REF: Categorical.is_dtype_equal -> categories_match_up_to_permutation #37545

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 9 commits into from
Nov 2, 2020
Prev Previous commit
Next Next commit
Merge branch 'master' of https://github.com/pandas-dev/pandas into cl…
…n-is_dtype_equal
  • Loading branch information
jbrockmendel committed Nov 2, 2020
commit 10cf22c13fa553607f98662047430254b8b38b61
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ Deprecations
- Deprecated slice-indexing on timezone-aware :class:`DatetimeIndex` with naive ``datetime`` objects, to match scalar indexing behavior (:issue:`36148`)
- :meth:`Index.ravel` returning a ``np.ndarray`` is deprecated, in the future this will return a view on the same index (:issue:`19956`)
- Deprecate use of strings denoting units with 'M', 'Y' or 'y' in :func:`~pandas.to_timedelta` (:issue:`36666`)
- :class:`Index` methods ``&``, ``|``, and ``^`` behaving as the set operations :meth:`Index.intersection`, :meth:`Index.union`, and :meth:`Index.symmetric_difference`, respectively, are deprecated and in the future will behave as pointwise boolean operations matching :class:`Series` behavior. Use the named set methods instead (:issue:`36758`)
- :meth:`Categorical.is_dtype_equal` and :meth:`CategoricalIndex.is_dtype_equal` are deprecated, use :meth:`Categorical.categories_match_up_to_permutation` instead (:issue:`37545`)

.. ---------------------------------------------------------------------------
Expand Down
14 changes: 3 additions & 11 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,17 +1706,9 @@ def _validate_listlike(self, target: ArrayLike) -> np.ndarray:
# Indexing on codes is more efficient if categories are the same,
# so we can apply some optimizations based on the degree of
# dtype-matching.
if self.categories.equals(target.categories):
# We use the same codes, so can go directly to the engine
codes = target.codes
elif self.categories_match_up_to_permutation(target):
# We have the same categories up to a reshuffling of codes.
codes = recode_for_categories(
target.codes, target.categories, self.categories
)
else:
code_indexer = self.categories.get_indexer(target.categories)
codes = take_1d(code_indexer, target.codes, fill_value=-1)
codes = recode_for_categories(
target.codes, target.categories, self.categories, copy=False
)
else:
codes = self.categories.get_indexer(target)

Expand Down 3A13
You are viewing a condensed version of this merge commit. You can view the full changes here.
0