Closed clemconv1 closed 2 days ago
Can you provide a more complete example?
I digged into that one as I remember having similar issues on a project but I was not able to fully reproduce with TimestampSeries
.
Instead here is a short example that can reproduce a similar error, @Dr-Irv let me know if this is something that we thrive to fix through an overload (I assume, haven't looked at the code in details).
import pandas as pd
df = pd.DataFrame({"date": pd.bdate_range("2024-09-01", "2024-09-10")})
df["date"] = pd.to_datetime(df["date"])
vv = pd.bdate_range("2024-09-01", "2024-09-10")
vv + pd.tseries.offsets.YearEnd(0)
which will raise the error:
Operator "+" not supported for types "DatetimeIndex" and "YearEnd"
https://github.com/pandas-dev/pandas-stubs/blob/5177d67a3189aee4037031ffd503f0af997c617b/pandas-stubs/core/indexes/datetimes.pyi#L58-L61
Likely could be added here as pd.tseries.offsets.YearEnd
is a class from the BaseOffset
base class and not Timedelta
.
Open to discussing if this is the correct approach.
Might be the same / similar as https://github.com/pandas-dev/pandas-stubs/issues/755
I digged into that one as I remember having similar issues on a project but I was not able to fully reproduce with
TimestampSeries
. Instead here is a short example that can reproduce a similar error, @Dr-Irv let me know if this is something that we thrive to fix through an overload (I assume, haven't looked at the code in details).import pandas as pd df = pd.DataFrame({"date": pd.bdate_range("2024-09-01", "2024-09-10")}) df["date"] = pd.to_datetime(df["date"]) vv = pd.bdate_range("2024-09-01", "2024-09-10") vv + pd.tseries.offsets.YearEnd(0)
which will raise the error:
Operator "+" not supported for types "DatetimeIndex" and "YearEnd"
Feel free to open a MR - I think this should work!
Might be the same / similar as #755
Not sure it is exactly the same, maybe under the hood they are related but I could not find obvious ways to tackle those two at once. I see that you have already opened a PR for your issue so I will leave that to you, you surely have more context on it!
It seems type annotations are wrong between a Timestamp series and tools offered by the offsets library, using
pyright
df["year_end"] = df["date"] + pd.tseries.offsets.YearEnd(0) is flagged with Operator "+" not supported for types "TimestampSeries" and "YearEnd"