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

subtract of BDay results in days instead of pd.Timestamp #4631

Closed
alippai opened this issue Jul 19, 2023 · 2 comments
Closed

subtract of BDay results in days instead of pd.Timestamp #4631

alippai opened this issue Jul 19, 2023 · 2 comments
Assignees

Comments

@alippai
Copy link

alippai commented Jul 19, 2023

Code Snippet

from pandas.tseries.offsets import BDay
import datetime

(datetime.date(2023,1,1) - BDay(7)).date() # this line reports `.date()` is not a member of `date`, but actually it's a `pd.Timestamp` and the code works, only Pylance in VSCode has a false positive
@github-actions github-actions bot added the needs repro Issue has not been reproduced yet label Jul 19, 2023
@debonte
Copy link
Contributor

debonte commented Jul 20, 2023

Pylance is working correctly here. We include the latest pandas-stubs in every Pylance release. In pandas-stubs, BDay inherits (indirectly) from BaseOffset which has the following __rsub__ overload:

_DatetimeT = TypeVar("_DatetimeT", bound=date)

# some lines removed for clarity

@overload
def __rsub__(self, other: _DatetimeT) -> _DatetimeT: ...

date doesn't have a __sub__ overload that handles pandas types (which makes sense since date comes from the stdlib), so we look for a matching __rsub__ and find this one which tells us that the result of a "date - BDay" subtraction operation will be a date.

If you feel that the stubs are incorrect, please file an issue on pandas-stubs.

@debonte debonte closed this as completed Jul 20, 2023
@debonte debonte added external bug and removed needs repro Issue has not been reproduced yet labels Jul 20, 2023
@alippai
Copy link
Author

alippai commented Jul 20, 2023

@debonte: indeed, the stub seems to be incorrect. Thanks for pointing me to the right direction.

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

No branches or pull requests

2 participants