Skip to content
Open
Changes from all 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
13 changes: 13 additions & 0 deletions pandas/tests/frame/methods/test_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,19 @@ def test_fillna_categorical_nan(self):
df = DataFrame({"a": Categorical(idx)})
tm.assert_frame_equal(df.fillna(value=NaT), df)

def test_fillna_with_categorical_series(self):
df = DataFrame(
Copy link
Member

Choose a reason for hiding this comment

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

Add a reference to the issue as a comment on the first line.

# https://github.com/pandas-dev/pandas/issues/56329

{"cats": Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, np.nan]}
)

filler = Series(Categorical([10.0, 20.0, 30.0]))
df.fillna({"ints": filler}, inplace=True)
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid mutating here; when debugging, it can be helpful to have both before and after the operation accessible.

Suggested change
df.fillna({"ints": filler}, inplace=True)
result = df.fillna({"ints": filler})


expected = DataFrame(
{"cats": Categorical(["A", "B", "C"]), "ints": [1.0, 2.0, 30.0]}
)
tm.assert_frame_equal(df, expected)

def test_fillna_no_downcast(self, frame_or_series):
# GH#45603 preserve object dtype
obj = frame_or_series([1, 2, 3], dtype="object")
Expand Down
Loading