Skip to content

TST: Retyping of categorical column with NaN #60112

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
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
12 changes: 12 additions & 0 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1243,3 +1243,15 @@ def test_loc_setitem_empty_labels_no_dtype_conversion():

assert df.a.dtype == "int64"
tm.assert_frame_equal(df, expected)


def test_categorical_nan_no_dtype_conversion():
# GH 43996

df = pd.DataFrame({"a": Categorical([np.nan], [1]), "b": [1]})
expected = pd.DataFrame({"a": Categorical([1], [1]), "b": [1]})
assert df["a"].dtype == "category"

df.loc[0, "a"] = 1
Copy link
Member

Choose a reason for hiding this comment

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

From the issue, this should test assigning a numpy array with an integer not just an integer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh right, I'll get that changed

assert df["a"].dtype == "category"
tm.assert_frame_equal(df, expected)