Skip to content

Commit 679ba77

Browse files
Backport PR #51568 on branch 2.0.x (ENH: Series.fillna with empty argument making deep copy) (#51580)
Backport PR #51568: ENH: Series.fillna with empty argument making deep copy Co-authored-by: Patrick Hoefler <[email protected]>
1 parent dcbff60 commit 679ba77

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pandas/core/generic.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6850,7 +6850,7 @@ def fillna(
68506850
# test_fillna_nonscalar
68516851
if inplace:
68526852
return None
6853-
return self.copy()
6853+
return self.copy(deep=None)
68546854
from pandas import Series
68556855

68566856
value = Series(value)

pandas/tests/copy_view/test_interp_fillna.py

+24
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,27 @@ def test_fillna_interval_inplace_reference(using_copy_on_write):
232232
assert np.shares_memory(
233233
get_array(ser, "a").left.values, get_array(view, "a").left.values
234234
)
235+
236+
237+
def test_fillna_series_empty_arg(using_copy_on_write):
238+
ser = Series([1, np.nan, 2])
239+
ser_orig = ser.copy()
240+
result = ser.fillna({})
241+
242+
if using_copy_on_write:
243+
assert np.shares_memory(get_array(ser), get_array(result))
244+
else:
245+
assert not np.shares_memory(get_array(ser), get_array(result))
246+
247+
ser.iloc[0] = 100.5
248+
tm.assert_series_equal(ser_orig, result)
249+
250+
251+
def test_fillna_series_empty_arg_inplace(using_copy_on_write):
252+
ser = Series([1, np.nan, 2])
253+
arr = get_array(ser)
254+
ser.fillna({}, inplace=True)
255+
256+
assert np.shares_memory(get_array(ser), arr)
257+
if using_copy_on_write:
258+
assert ser._mgr._has_no_reference(0)

0 commit comments

Comments
 (0)