Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check incorrect when using a TimestampSeries and YearEnd from pandas.tseries.offsets #969

Closed
clemconv1 opened this issue Aug 5, 2024 · 6 comments · Fixed by #1004
Closed

Comments

@clemconv1
Copy link

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"

  • OS: MacOS
  • OS Version 13.5
  • python 3.9.19
  • pylance version v2024.7.1
@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Aug 5, 2024

Can you provide a more complete example?

@loicdiridollou
Copy link
Contributor

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"

@loicdiridollou
Copy link
Contributor

@overload
def __add__(
self, other: timedelta | Timedelta | TimedeltaIndex
) -> DatetimeIndex: ...

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.

@alippai
Copy link
Contributor

alippai commented Sep 13, 2024

Might be the same / similar as #755

@twoertwein
Copy link
Member

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!

@loicdiridollou
Copy link
Contributor

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants