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
import numpy
print(pandas.to_datetime(numpy.nan, unit="s"))
Issue Description
Converting a value of floating type to integer type which is out of range for the integer type is undefined, see 6.3.1.4 Real floating and integer.
You can use gcc92.fsffrance.org for your tests if don't have your own hardware, or use qemu with the images from https://download.opensuse.org/ports/riscv/tumbleweed/images/.
$ python3 -c 'import pandas
import numpy
print(pandas.to_datetime(numpy.nan, unit="s"))'
Traceback (most recent call last):
File "<string>", line 3, in <module>
File "/usr/lib64/python3.10/site-packages/pandas/core/tools/datetimes.py", line 1078, in to_datetime
result = convert_listlike(np.array([arg]), format)[0]
File "/usr/lib64/python3.10/site-packages/pandas/core/tools/datetimes.py", line 357, in _convert_listlike_datetimes
return _to_datetime_with_unit(arg, unit, name, tz, errors)
File "/usr/lib64/python3.10/site-packages/pandas/core/tools/datetimes.py", line 530, in _to_datetime_with_unit
arr, tz_parsed = tslib.array_with_unit_to_datetime(arg, unit, errors=errors)
File "pandas/_libs/tslib.pyx", line 266, in pandas._libs.tslib.array_with_unit_to_datetime
pandas._libs.tslibs.np_datetime.OutOfBoundsDatetime: cannot convert input with unit 's'
Expected Behavior
No error.
Installed Versions
Comment From: phofl
Hi, thanks for your report. This works on 1.4.3 and main for me. Can you please recheck, that you have pandas 1.4.3 installed?
Comment From: andreas-schwab
Of course I have, why do you ask?
Comment From: phofl
Because it works for me on 1.4.3, 1.4.4 and main
Comment From: andreas-schwab
How did you test that?
Comment From: phofl
I executed the code snippet from your post?
Comment From: andreas-schwab
Where did you execute it? In qemu or on real hardware?
Comment From: phofl
Macos
Comment From: phofl
I executed it on a macOS os
Comment From: andreas-schwab
What hardware?
Comment From: andreas-schwab
There is macos for RISC-V???
Comment From: andreas-schwab
Did you actually read the report?
Comment From: andreas-schwab
Please use gcc92.fsffrance.org for your tests if don't have your own hardware.
Comment From: phofl
There is a code snippet, nothing else. I read the versions, but if you think that this is specific to your hardware, a small explanation would have been nice. Your report reads like a general issue, which is not the case.
could you adjust your issue title and add a small explanation?
you could also try debugging it yourself if you are interested
Comment From: andreas-schwab
You can also use one of the images in https://download.opensuse.org/ports/riscv/tumbleweed/images/ with qemu.
Comment From: andreas-schwab
This is a general issue because it depends on undefined behaviour (converting NaN value to integer).
Comment From: phofl
It works on my machine, so seems to be hardware dependent
Comment From: andreas-schwab
Depending on undefined behaviour is a bug.
Comment From: andreas-schwab
$ python3 -c $'import numpy\nprint(numpy.asarray(numpy.nan).astype("i8"))' 9223372036854775807
Comment From: jreback
@andreas-schwab we don't support this hardware in any way
you can submit a patch if u can find the problem
Comment From: andreas-schwab
This has nothing to do with hardware support. This is undefined behaviour. Depending on undefined behaviour is a serious bug.
Comment From: phofl
You are welcome to submit a pr, if you can identify the bug and provide a fix.
Comment From: MarcoGorelli
@andreas-schwab could you please clarify? What commits is this diff between, what's it meant to show? I've formatted your code to make it easier to read, but - apologies for not understanding - I still don't see your point. Could you clarify what exactly you're expecting pandas to do?
Did you actually read the report?
please be respectful
Comment From: andreas-schwab
Your reaction to the bug report has been far from respectful so far.
Comment From: phofl
Could you please update the top post with steps how to reproduce the bug if you are on windows/ubuntu/macOS? This will help someone who wants to work on this. We have tests covering this case in the ci, so simply executing the code snippet won't be sufficient.
Additionally, it would be great if you could add an explanation on what you are referring to with undefined behaviour, this is not clear to me. Some context to the code snippet you posted earlier would also be helpful.
Comment From: andreas-schwab
Converting a value of floating type to integer type which is out of range for the integer type is undefined, see 6.3.1.4 Real floating and integer.
Comment From: andreas-schwab
You can use gcc92.fsffrance.org for your tests if don't have your own hardware, or use qemu with the images from https://download.opensuse.org/ports/riscv/tumbleweed/images/.
Comment From: phofl
I copied it into the top post in case someone wants to work on this