Skip to content

BUG: Categorical of booleans has object .categories #46422

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 5 commits into from
Mar 20, 2022
Merged
Changes from 3 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
12 changes: 12 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1107,3 +1107,15 @@ def test_compare_complex_dtypes():

with pytest.raises(TypeError, match=msg):
df.lt(df.astype(object))


def test_categorical_of_booleans_is_boolean():
# https://github.com/pandas-dev/pandas/issues/46313
df = pd.DataFrame(
{"int_cat": [1, 2, 3], "bool_cat": [True, False, False]}, dtype="category"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to pandas/tests/series/accessors/test_cat_accessor.py

)
value = df["bool_cat"].cat.categories.dtype
expected = np.dtype(np.bool_)
not_expected = np.dtype(np.object_)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the not expected case

assert value is expected
assert value is not not_expected