Skip to content

obj.fillna(fill_value) doesn't shallow copy if obj is an empty Series #32543

Closed
@SaturnFromTitan

Description

@SaturnFromTitan

While working on #32483 I bumped into the following issue:

Code Sample, a copy-pastable example if possible

obj = pd.Series()
result = obj.fillna(0)
assert obj is not result  # raises AssertionError

Problem description

See test_fillna in the mentioned PR (or master when it is merged): With any value of obj, even if it is an empty Index the shallow copy is executed. This can potentially yield bugs related to unintended mutations of obj further down the road.

Output of pd.show_versions()

INSTALLED VERSIONS

commit : 343dd67
python : 3.7.6.final.0
python-bits : 64
OS : Darwin
OS-release : 19.3.0
Version : Darwin Kernel Version 19.3.0: Thu Jan 9 20:58:23 PST 2020; root:xnu-6153.81.5~1/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : de_DE.utf-8
LANG : de_DE.utf-8export
LOCALE : de_DE.UTF-8

pandas : 1.1.0.dev0+698.g343dd6751.dirty
numpy : 1.17.5
pytz : 2019.3
dateutil : 2.8.1
pip : 20.0.1
setuptools : 45.1.0.post20200119
Cython : 0.29.14
pytest : 5.3.5
hypothesis : 5.3.0
sphinx : 2.3.1
blosc : None
feather : None
xlsxwriter : 1.2.7
lxml.etree : 4.4.2
html5lib : 1.0.1
pymysql : None
psycopg2 : None
jinja2 : 2.10.3
IPython : 7.11.1
pandas_datareader: None
bs4 : 4.8.2
bottleneck : 1.3.1
fastparquet : 0.3.2
gcsfs : None
matplotlib : 3.1.2
numexpr : 2.7.1
odfpy : None
openpyxl : 3.0.1
pandas_gbq : None
pyarrow : 0.15.1
pytables : None
pyxlsb : None
s3fs : 0.4.0
scipy : 1.4.1
sqlalchemy : 1.3.13
tables : 3.6.1
tabulate : 0.8.6
xarray : 0.14.1
xlrd : 1.2.0
xlwt : 1.3.0
numba : 0.47.0

Metadata

Metadata

Labels

Missing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions