delegate (most) datetimelike Series arithmetic ops to DatetimeIndex by jbrockmendel · Pull Request #18817 · pandas-dev/pandas (original) (raw)

The other arithmetic PRs are a couple steps away from really being ready for this. The only part of this that is separately actionable (and on which I need input) is for where (and I guess if) to fix the mismatched behavior in DatetimeIndex.__add__ and __sub__

rng = pd.date_range('2000-01-01 09:00', freq='H', periods=2, tz='US/Pacific')
ser = pd.Series(rng)
other = np.array(1, dtype=np.int64)

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

>>> rng + other
DatetimeIndex(['2000-01-01 17:00:00.000000001-08:00', '2000-01-01 18:00:00.000000001-08:00'], dtype='datetime64[ns, US/Pacific]', freq=None)

>>> other + rng
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'numpy.ndarray' and 'DatetimeIndex'

This PR addressed that here and here, but got some pushback because it was (admittedly) ugly. Alternative suggestions requested.

Closing this PR, will (eventually) open another one with reduced scope.