8000 BUG: CategoricalIndex.equals casting non-categories to np.nan by jbrockmendel · Pull Request #37667 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: CategoricalIndex.equals casting non-categories to np.nan #37667

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 4 commits into from
Nov 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
GH ref
  • Loading branch information
jbrockmendel committed Nov 6, 2020
commit 11a492ad2fa6e13e35638a669cfc8a2019ed9367
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ Categorical
^^^^^^^^^^^
- :meth:`Categorical.fillna` will always return a copy, will validate a passed fill value regardless of whether there are any NAs to fill, and will disallow a ``NaT`` as a fill value for numeric categories (:issue:`36530`)
- Bug in :meth:`Categorical.__setitem__` that incorrectly raised when trying to set a tuple value (:issue:`20439`)
- Bug in :meth:`CategoricalIndex.equals` incorrectly casting non-category entries to ``np.nan`` (:issue:`???`)
- Bug in :meth:`CategoricalIndex.equals` incorrectly casting non-category entries to ``np.nan`` (:issue:`37667`)

Datetimelike
^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def _is_dtype_compat(self, other) -> Categorical:
other = other._values

if not ((other == values) | (isna(other) & isna(values))).all():
# GH#???? see test_equals_non_category
# GH#37667 see test_equals_non_category
raise TypeError(
"categories must match existing categories when appending"
)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/indexes/categorical/test_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,8 @@ def test_equals_categorical_unordered(self):
assert not b.equals(c)

def test_equals_non_category(self):
# Case where other contains a value not among ci's categories ("D") and
# also contains np.nan
# GH#37667 Case where other contains a value not among ci's
# categories ("D") and also contains np.nan
ci = CategoricalIndex(["A", "B", np.nan, np.nan])
other = Index(["A", "B", "D", np.nan])

Expand Down
0