Open sfc-gh-mvashishtha opened 3 weeks ago
Confirmed on main - further investigations and PRs to fix are welcome!
I also found that timestamp + timedelta
and timestamp - timedelta
raise a similar error, ufunc 'add' cannot use operands with types dtype('<m8[ns]') and dtype('float64')
import pandas as pd
pd.DataFrame([pd.Timestamp(1)]) + pd.Series([pd.Timedelta(2), pd.Timedelta(3)])
pd.DataFrame([pd.Timestamp(1)]) - pd.Series([pd.Timedelta(2), pd.Timedelta(3)])
take
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
Issue Description
I'm getting
TypeError: cannot subtract DatetimeArray from ndarray
.Doing the subtraction in the opposite direction (series - dataframe) gives
UFuncTypeError: ufunc 'subtract' cannot use operands with types dtype('<M8[ns]') and dtype('float64')
.I found a related issue https://github.com/pandas-dev/pandas/issues/31623.
Expected Behavior
This subtraction should work the way it would for integers:
so for datetimes we should align the series on axis 1 and broadcast it to each row to get an output of
Installed Versions