Skip to content

ENH: Series.fillna with empty argument making deep copy #51568

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 1 commit into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6859,7 +6859,7 @@ def fillna(
# test_fillna_nonscalar
if inplace:
return None
return self.copy()
return self.copy(deep=None)
from pandas import Series

value = Series(value)
Expand Down
24 changes: 24 additions & 0 deletions pandas/tests/copy_view/test_interp_fillna.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,27 @@ def test_fillna_interval_inplace_reference(using_copy_on_write):
assert np.shares_memory(
get_array(ser, "a").left.values, get_array(view, "a").left.values
)


def test_fillna_series_empty_arg(using_copy_on_write):
ser = Series([1, np.nan, 2])
ser_orig = ser.copy()
result = ser.fillna({})

if using_copy_on_write:
assert np.shares_memory(get_array(ser), get_array(result))
else:
assert not np.shares_memory(get_array(ser), get_array(result))

ser.iloc[0] = 100.5
tm.assert_series_equal(ser_orig, result)


def test_fillna_series_empty_arg_inplace(using_copy_on_write):
ser = Series([1, np.nan, 2])
arr = get_array(ser)
ser.fillna({}, inplace=True)

assert np.shares_memory(get_array(ser), arr)
if using_copy_on_write:
assert ser._mgr._has_no_reference(0)