Skip to content

Fixed regression in Series.duplicated for categorical dtype with bool categories #44356

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
Nov 12, 2021
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.3.5.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Fixed regressions
~~~~~~~~~~~~~~~~~
- Fixed regression in :meth:`Series.equals` when comparing floats with dtype object to None (:issue:`44190`)
- Fixed performance regression in :func:`read_csv` (:issue:`44106`)
- Fixed regression in :meth:`Series.duplicated` when Series has :class:`Categorical` dtype with boolean categories (:issue:`44351`)
-

.. ---------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _ensure_data(values: ArrayLike) -> np.ndarray:
# i.e. all-bool Categorical, BooleanArray
try:
return np.asarray(values).astype("uint8", copy=False)
except TypeError:
except (TypeError, ValueError):
# GH#42107 we have pd.NAs present
return np.asarray(values)

Expand Down
18 changes: 17 additions & 1 deletion pandas/tests/series/methods/test_duplicated.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import numpy as np
import pytest

from pandas import Series
from pandas import (
NA,
Categorical,
Series,
)
import pandas._testing as tm


Expand Down Expand Up @@ -33,3 +37,15 @@ def test_duplicated_nan_none(keep, expected):

result = ser.duplicated(keep=keep)
tm.assert_series_equal(result, expected)


def test_duplicated_categorical_bool():
# GH#44351
ser = Series(
Categorical(
[True, False, True, False, NA], categories=[True, False], ordered=True
)
)
result = ser.duplicated()
expected = Series([False, False, True, True, False])
tm.assert_series_equal(result, expected)