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 missing __hash__ stubs #746

Merged
merged 1 commit into from
Jul 18, 2023
Merged

Add missing __hash__ stubs #746

merged 1 commit into from
Jul 18, 2023

Conversation

TheTripleV
Copy link
Contributor

These missing __hash__ methods are in the pandas stubs but are missing here. The missing __hash__es incorrectly marked these classes as being unhashable.

microsoft/pyright#5513 (comment)

@@ -386,6 +386,7 @@ class Timedelta(timedelta):
) -> npt.NDArray[np.bool_]: ...
@overload
def __gt__(self, other: TimedeltaSeries | Series[pd.Timedelta]) -> Series[bool]: ...
def __hash__(self) -> int: ...
Copy link
Member

Choose a reason for hiding this comment

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

Can you please explain why this is needed: Timedelta inherits from datetime.timedelta which declares to have __hash__ see typeshed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

According to the stubs, Timedelta does not inherit __hash__ from datetime.timedelta because Timedelta defines __eq__ (https://github.com/pandas-dev/pandas-stubs/pull/746/files#diff-0321b1cf2f2c79264daae754a98c26bcac7040336168706d7f12408919c01ad4L313).

Classes that define __eq__ do not inherit __hash__. Python Docs

Copy link
Member

Choose a reason for hiding this comment

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

okay, I understand it now, if __eq__ is overwritten, __hash__ is set to None unless it is explicitly declared.

can you please add two quick tests for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@twoertwein this is in the pandas repo, so I see no reason not to accept this.

Copy link
Member

Choose a reason for hiding this comment

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

I'm for accepting, but typically we like to have tests?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm for accepting, but typically we like to have tests?

Yes, but in this case, I'm OK to skip the tests.

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.

will merge this pending answer from @twoertwein

@twoertwein twoertwein merged commit 8d5a827 into pandas-dev:main Jul 18, 2023
13 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.

3 participants