feat(api): add name
argument to topk
/value_counts
#10083
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a new
name
argument totopk
&value_counts
. Fixes #9948.I think adding a
name
arg to these helpers makes sense. For other builtin aggregate methods you can chain a.name("myname")
call on the end, but in these cases the return type is aTable
. Adding an option to specify the name of the new column is nice for ux.I opted to go for a simple
name: str | None
version, rather than supporting format strings/callables likerename
. If a user wants to programmatically generate the name then they can do so themselves outside of this method. Keep it simple.One open question is whether this argument should be keyword only. I went with positional or keyword for now, no strong thoughts.
Also added a docstring example for
topk
while I was at it.