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

Add datetime.date and datetime.datetime specializations #1003

Merged
merged 4 commits into from
Oct 14, 2024

Conversation

alippai
Copy link
Contributor

@alippai alippai commented Sep 13, 2024

@twoertwein
Copy link
Member

Can you please add runtime tests in https://github.com/pandas-dev/pandas-stubs/blob/main/tests/test_timefuncs.py

You will also need to re-order the overloads to have the more specifiy overloads before more general overloads as type checker pick the first fitting overload (see the mypy errors).

@alippai
Copy link
Contributor Author

alippai commented Sep 14, 2024

@twoertwein thanks, I've updated the failing test and added the two cases brought up in the initial issue. Looks like datetime is a subclass of date so I just removed that, it could fix the overloads.

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your tests are still failing. I think the issue here is that this line is incorrect in offsets.pyi:

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

I think it should be

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

based on what is now in the pandas source.

Can you try that change to see if it will make things work? Because the error you are getting is that this overload: def __add__(self, other: _DatetimeT) -> _DatetimeT: ... will never get matched, because you put in something explicit for date, but datetime is a subclass of date, so I think changing the TypeVar line will fix it.

@alippai
Copy link
Contributor Author

alippai commented Oct 8, 2024

Looks like this is not possible to describe correctly: microsoft/pylance-release#6512

@Dr-Irv
Copy link
Collaborator

Dr-Irv commented Oct 8, 2024

Looks like this is not possible to describe correctly: microsoft/pylance-release#6512

I'm OK with putting in the appropriate #type: ignore and #pyright: ignore statements when the type checkers are reporting overlapping overloads.

@alippai
Copy link
Contributor Author

alippai commented Oct 13, 2024

@Dr-Irv thanks for the guide, I believe the last commit may work as intended and pass the CI

Copy link
Collaborator

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @alippai

@Dr-Irv Dr-Irv merged commit f71224c into pandas-dev:main Oct 14, 2024
10 checks passed
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 this pull request may close these issues.

BDay typing
3 participants