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
>>> pd.Series(
... [pd.Period("2012-1-1", freq="D"), pd.Period("2012-1-2", freq="D")]
... ).diff()
C:\Anaconda3\envs\pandasstubs\lib\site-packages\pandas\core\arrays\datetimelike.py:1306: RuntimeWarning: overflow encountered in scalar multiply
new_data = np.array([self.freq.base * x for x in new_i8_data])
0 NaT
1 <Day>
dtype: object
Issue Description
This error only appears on Windows, not on Linux!
Discovered in a pandas-stubs
pull request: https://github.com/pandas-dev/pandas-stubs/pull/907/files#r1571049325
Expected Behavior
No error message
Installed Versions
Comment From: Aloqeely
I think what's happening internally is that the values in the PeriodArray
are converted to int64 values to perform some calculations, and NaT
gets converted to a very big value (largest int64 number I think), and then it does some multiplication which will result in overflow for this NaT
(2^63
), which doesn't really affect anything as that value gets masked right after the multiplication, but the warning is quite misleading.
I think we can solve this by either performing the masking before doing the multiplication, or by doing the multiplication for all non-NaT values.
But I don't know why it happens for Windows only