date_range produces wrong values when overflowing · Issue #14187 · pandas-dev/pandas (original) (raw)
In the following case, you now get a RuntimeWarning. But shouldn't we rather error on this?
In [23]: pd.date_range('1/1/2000', periods=100000, freq='D')
/home/joris/scipy/pandas/pandas/tseries/index.py:1944: RuntimeWarning: overflow encountered in long_scalars
e = b + np.int64(periods) * stride
/home/joris/scipy/pandas/pandas/tseries/index.py:1954: RuntimeWarning: overflow encountered in long_scalars
data = np.arange(b, e, stride, dtype=np.int64)
Out[23]:
DatetimeIndex([ '2000-01-01 00:00:00',
'2000-01-02 00:00:00',
'2000-01-03 00:00:00',
'2000-01-04 00:00:00',
'2000-01-05 00:00:00',
'2000-01-06 00:00:00',
'2000-01-07 00:00:00',
'2000-01-08 00:00:00',
'2000-01-09 00:00:00',
'2000-01-10 00:00:00',
...
'1689-03-17 00:25:26.290448384',
'1689-03-18 00:25:26.290448384',
'1689-03-19 00:25:26.290448384',
'1689-03-20 00:25:26.290448384',
'1689-03-21 00:25:26.290448384',
'1689-03-22 00:25:26.290448384',
'1689-03-23 00:25:26.290448384',
'1689-03-24 00:25:26.290448384',
'1689-03-25 00:25:26.290448384',
'1689-03-26 00:25:26.290448384'],
dtype='datetime64[ns]', length=100000, freq='D')
In [24]: pd.__version__
Out[24]: '0.19.0rc1+2.gd8cd33b'
In [25]: np.__version__
Out[25]: '1.11.1'