Skip to content

Make Series.groupby.transform annotation more precise #459

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

Closed
wants to merge 1 commit into from

Conversation

gandhis1
Copy link
Contributor

@gandhis1 gandhis1 commented Dec 5, 2022

"std",
"sum",
"var",
# Transformation functions
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is another area where I really think a static analysis tool ought to save you from yourself and prevent you from making an illogical call. In this case, we could allow aggregation functions like sum because they work with transform(), however they make no sense to use as a transformation function.

Similar to the last PR, I am allowing it, because pandas permits it and returns a value without erroring. But I'm personally not a big fan of that.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You could always bring it up as a pandas issue for discussion.

*args: Any, # Ideally we would use P.args here, but it does not work with engine/engine_kwargs present
engine: Literal["cython", "numba", None] = ...,
engine_kwargs: dict[str, Any] | None = ...,
**kwargs: Any, # Ideally we would use P.kwargs here, but does not work with engine/engine_kwargs present
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was working great when I did not have engine and engine_kwargs in there because I could use P.args and P.kwargs as the annotation. However, I'm having trouble getting that working with these additional keyword arguments in there. Any ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

**kwargs: dict[str, Any]. You might need a **, before engine.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or maybe place engine and engine_kwargs before *args and **kwargs ???

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Or maybe place engine and engine_kwargs before *args and **kwargs ???

So pyright no longer complains about that, but then the test doesn't work, because it thinks engine and engine_kwargs are positional parameters.

Still investigating...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it isn't possible. Here is a similar issue: microsoft/pyright#4189

The relevant part of PEP 612:

Inside of bar, we would get TypeError: foo() got multiple values for argument 'x'. Requiring these concatenated arguments to be addressed positionally avoids this kind of problem, and simplifies the syntax for spelling these types. Note that this also why we have to reject signatures of the form (*args: P.args, s: str, **kwargs: P.kwargs) (See Concatenating Keyword Parameters for more details).

This is unfortunate. I'll have to revert back to using Any.

@gandhis1
Copy link
Contributor Author

gandhis1 commented Feb 8, 2023

I'm going to close this until I can dedicate the time to get this to the finish line.

@gandhis1 gandhis1 closed this Feb 8, 2023
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