Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] 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 pandas as pd
import numpy as np
print(pd.__version__, np.__version__)
df = pd.DataFrame({'name': ['Raphael', 'Donatello'],
'weapon': [22.5, np.NAN],
'mask': ['red', 'purple'],
})
df.to_csv('asdf.csv')
Issue Description
Running the above code runs just fine when numpy < 1.24 is used.
Using the latest version of numpy, it's causing a RuntimeWarning on to_csv (due to the NaN).
site-packages/pandas/core/internals/blocks.py:2323: RuntimeWarning: invalid value encountered in cast
values = values.astype(str)
Expected Behavior
No runtime error when using the latest numpy>=1.24
Installed Versions
Comment From: phofl
Hi, thanks for your report. I can't reproduce on Mac. I checked your ci where this is actually raising. Could you maybe post a reproducible example for this?
Comment From: xmatthias
@phofl the above sample does reproduce the runtime error reliably for me - not sure what else you need?
if it's not showing - are you sure your numpy is 1.24.0 ? above reproduction:
Comment From: asishm
xref: https://github.com/numpy/numpy/issues/22843
Comment From: phofl
Yeah checked multiple times and in 2 different environments, but closing here since it’s fixed in numpy
Comment From: asishm
fwiw - this consistently reproduces for me with pd.DataFrame({'a': ['foo'], 'b': [np.nan]}).to_csv()
In [55]: pd.DataFrame({'a': ['foo'], 'b': [np.nan]}).to_csv()
/home/asishm/pandas-asishm/pandas/core/internals/blocks.py:2239: RuntimeWarning: invalid value encountered in cast
values = values.astype(str)
Out[55]: ',a,b\n0,foo,\n'
In [57]: pd.__version__, np.__version__
Out[57]: ('2.0.0.dev0+971.gca3e0c875f', '1.24.0')
on wsl2