-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
ENH: pd.NamedAgg forwards *args and **kwargs to aggfunc #58852
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
Conversation
@@ -108,7 +108,12 @@ | |||
ScalarResult = TypeVar("ScalarResult") | |||
|
|||
|
|||
class NamedAgg(NamedTuple): | |||
class _BaseNamedAgg(NamedTuple): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for introducing a new class here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's because you cannot override new when inheriting from NamedTuple directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the most elegant way I found to override it while maintaining the NamedTuple properties was to Introduce a new class. Do you have a suggestion for another method to do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reference error for when I tried to inherit directly from NamedTuple is:
AttributeError: Cannot overwrite NamedTuple attribute __new__
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that's unfortunate. This seems kind of hacky as a result though - maybe we can just drop the NamedTuple subclass? I think that was mostly developed that way as a convenience rather than an intentional design decision - I am not sure why NamedAgg would need to be "tuple-ish"
@rhshadrach might have more thoughts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
python/cpython#77258 has some relevant information, especially the linked discussion there to the issue in python/typing
.
In any case, it looks to me like this implementation just ignores args
/ kwargs
when the provided aggfunc
is not a callable? If that's the case, then I'm -1 on this approach anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhshadrach I'll rethink the approach to include the function names passed as string.
I'm not sure I understand your thoughts on the necessity of keeping NamedArgs with tuple behavior. Could you clarify that?
TY
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand your thoughts on the necessity of keeping NamedArgs with tuple behavior. Could you clarify that?
I don't believe I shared any thoughts in this regard, just a link to some background information on why Python raises when you try to overwrite __new__
.
This pull request is stale because it has been open for thirty days with no activity. Please update and respond to this comment if you're still interested in working on this. |
Closing as stale. @tomytp - if you'd like to continue, comment here and we can reopen. |
doc/source/whatsnew/v3.0.0.rst
file if fixing a bug or adding a new feature.