Skip to content
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

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

Closed
SaturnFromTitan opened this issue Mar 8, 2020 · 1 comment · Fixed by #32733
Closed

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

SaturnFromTitan opened this issue Mar 8, 2020 · 1 comment · Fixed by #32733
Assignees
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Milestone

Comments

@SaturnFromTitan
Copy link
Contributor

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

@SaturnFromTitan
Copy link
Contributor Author

take

SaturnFromTitan added a commit to SaturnFromTitan/pandas that referenced this issue Mar 15, 2020
@jreback jreback added the Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate label Mar 16, 2020
@jreback jreback added this to the 1.1 milestone Mar 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Missing-data np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants