Skip to content

Expand drop() overloads to encode more argument restriction and add type parameters to df.drop() signature. #951

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

Merged
merged 3 commits into from
Jun 29, 2024

Conversation

JanEricNitschke
Copy link
Contributor

  • Closes #xxxx (Replace xxxx with the Github issue number)
  • Tests added: Please use assert_type() to assert the type of any return value

This is again to increase compatibility with pyright strict mode. I verified that the df.drop tests do not pass pyright strict without this change but do with it.

Also (maybe) closes #950.

This is done by adding a bunch of overloads that specify the allowed combinations in more detail.

For that i added a test that fails without this change and passes with it,

However i was not able to specify the full functionality using the overloads. Specifically, explicit "None" arguments are allowed by the signature, but cause errors at runtime. This is mostly because None is Hasheable.
This could be improved substantially in correctness and conciseness of the hints if it were possible to type hint the general signature using Non-None-Hasheable | None and then split these up in the overloads.

@JanEricNitschke
Copy link
Contributor Author

JanEricNitschke commented Jun 29, 2024

One more thing that could be done would be to add overloads for the cases where the Nones are explicitely specified and mark that as deprecated and Never return. But i dont know how clear that would be. See: microsoft/pyright#8265

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.

@Dr-Irv Dr-Irv merged commit 7e5b771 into pandas-dev:main Jun 29, 2024
13 checks passed
@JanEricNitschke JanEricNitschke deleted the fix-frame-drop branch June 29, 2024 18:41
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.

df.drop signature does not capture all constraints
2 participants