-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: numpy>1.24 triggers RuntimeWarning
when converting NaN via pd.to_datetime()
#50702
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
Comments
thanks for the report @fpavogt |
Just noticed the push to milestone 3.0 ... I guess this is driven by the fact that 2.0 is overdue, and there is no formal work on this issue just yet ? Since this issue is making a mess of my code, I might be able to find the time to submit a PR for it (rather than patch it hastily on my end). But I'll admit that the possibility of floating point errors dampens a bit my enthusiasm to have this be my first contribution to pandas ... pandas gurus: is there any future in the work-around suggested above ? |
Hey, I don't think anyone has worked on this yet, and it's not a blocker for the 2.0 release. This doesn't mean you'll need to wait until 3.0, if someone suggests a fix it could land in 2.1 / 2.2 / etc... Pinging @jbrockmendel , but also @rebecca-palmer who's done some seriously careful and high-quality work in this space |
I think this was recently fixed in #51006 ... with warnings.catch_warnings(), which we might not want for a different reason: it's not thread-safe. It might be better to use with np.errstate(all='ignore'), but I don't know whether that's thread-safe or not. I think @fpavogt 's
|
Is there a way to easily test for rounding errors that is platform independent ? I suppose I could find an example on my machine, but would it really make a useful addition to the test suite ? As per the |
If there's a bug on a particular platform I'd rather know about it then not, even if we don't have it in the CI. So go for it. The .round(0) solution seems like a hack to me. Best guess is long-term we're going to need a vectorized version of cast_from_unit in the cython code. |
Hey @jbrockmendel, To to avoid any misunderstandings down the line: I am not aware of any rounding issue bug on my platform at this point ... I merely meant I could try to find one, if it is of concern. |
I am not seeing this on the main version of pandas with numpy 1.25
|
I confirm that I am also no longer seeing this with pandas 2.0.3 and numpy 1.25.1. This ticket can thus probably be closed. Unless the questions raised by @rebecca-palmer regarding the use of |
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
Issue Description
The following change in numpy>1.24 is triggering a
RuntimeWarning
when trying to convert anp.nan
to a pandas datetime object.The cause of the problem (numpy change) is similar to #50681, but the fix on the pandas side is distinct. Hence this new issue.
Expected Behavior
No warning should be issued. I believe this could be fixed by not using
.astype(np.int64)
, but rather.round(0)
in the relevant part of the code (l.902-916 in core/arrays/timedeltas.py). Unless this would lead to precision issues, as warned in the comments ?Edit: The
.view()
command leads to floating point errors at times (with my new proposition of code). Using.astype()
seems to work better ... but some more thoughts is likely required to find a solid solution.Installed Versions
INSTALLED VERSIONS
commit : 8dab54d
python : 3.10.6.final.0
python-bits : 64
OS : Darwin
OS-release : 22.1.0
Version : Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:54 PDT 2022; root:xnu-8792.41.9~2/RELEASE_X86_64
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.UTF-8
pandas : 1.5.2
numpy : 1.24.1
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.6.3
pip : 22.3.1
Cython : None
pytest : 7.2.0
hypothesis : None
sphinx : 5.3.0
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.6.0
pandas_datareader: None
bs4 : None
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.6.1
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.3
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None
The text was updated successfully, but these errors were encountered: