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

BUG: np.nan_to_num change pandas DataFrame in place when copy = True #59932

Open
3 tasks done
lil-blue-curve opened this issue Oct 1, 2024 · 4 comments
Open
3 tasks done
Labels
Bug Compat pandas objects compatability with Numpy or Python functions

Comments

@lil-blue-curve
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

import numpy as np
import pandas as pd

x = pd.DataFrame([np.nan])
np.nan_to_num(x, copy=True)
print(x)

Issue Description

Result x is changed to 0.0 even when nan_to_num is called with copy=True.

This issue is originally reported to numpy here. Looks like pandas ignores copy=True NumPy passes?

Expected Behavior

x should not be changed when copy=True.

Installed Versions

INSTALLED VERSIONS

commit : 0691c5c
python : 3.11.8
python-bits : 64
OS : Linux
OS-release : 5.10.0-smp-1100.466.602.1
Version : #1 [v5.10.0-1100.466.602.1] SMP @1708156698
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : None
LOCALE : en_US.UTF-8

pandas : 2.2.3
numpy : 2.1.1
pytz : 2024.1
dateutil : 2.8.1
pip : None
Cython : None
sphinx : None
IPython : None
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : 5.3.0
matplotlib : None
numba : None
numexpr : 2.8.7
odfpy : None
openpyxl : 3.1.2
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.13.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : 2.0.1
xlsxwriter : None
zstandard : None
tzdata : None
qtpy : None
pyqt5 : None

@asishm
Copy link
Contributor

asishm commented Oct 1, 2024

Thanks, this seems to be related to #57739

@asishm asishm added the Compat pandas objects compatability with Numpy or Python functions label Oct 1, 2024
@rhshadrach rhshadrach removed the Needs Triage Issue that has not been reviewed by a pandas team member label Oct 1, 2024
@chaoyihu
Copy link
Contributor

chaoyihu commented Oct 14, 2024

This issue no longer exists on the main branch as of 2a10e04. The script returns:

    0
0 NaN

@asishm
Copy link
Contributor

asishm commented Oct 15, 2024

This issue no longer exists on the main branch as of 2a10e04. The script returns:

    0
0 NaN

I saw in one of your edits that you have numpy 1.26.4
This issue only should only occur with numpy 2.0+

@chaoyihu
Copy link
Contributor

I saw in one of your edits that you have numpy 1.26.4 This issue only should only occur with numpy 2.0+

I see. Sorry for the noise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Compat pandas objects compatability with Numpy or Python functions
Projects
None yet
Development

No branches or pull requests

4 participants