Fix incorrect exception raised by Series[datetime64] + int by jbrockmendel · Pull Request #19147 · pandas-dev/pandas (original) (raw)

Series[datetime64] +/- int is currently raising a ValueError when it should be raising a TypeError. This was introduced in #19024.

In the process of fixing this bug, this also goes most of the way towards fixing #19123 by raising on add/sub with integer arrays.

Setup:

dti = pd.date_range('2016-01-01', periods=2)
ser = pd.Series(dti)

ATM:

>>> ser + 1
[...]
ValueError: Cannot shift with no freq

After this PR (and also in 0.22.0 and anything before #19024):

>>> ser + 1
[...]
TypeError: incompatible type for a datetime/timedelta operation [__add__]