refactor(python): Deprecate non-keyword args for some functions #6851
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.
Keyword-only strategy
My philosophy for marking arguments as keyword-only is as follows, roughly in order of priority:
1. If parameters clash, at least one of the parameters should be keyword-only.
join(left_on, right_on, on)
-> eitheron
must be keyword-only, orleft_on
andright_on
.join(None, None, "a")
2. Boolean flags should always be keyword-only
sort(reverse=False, nulls_last=False)
sort(True, False)
-> which flags mean what?3. Keyword arguments that are rarely used or only used for very specific use cases should be keyword-only
read_csv(sample_size=1024)
4. Arguments after "single or sequence" arguments should be keyword-only
unique(subset, keep, maintain_order)
->keep
andmaintain_order
will be keyword-onlyunique("a", "b")
-> "b" will be passed tokeep
*args
syntax, see More ergonomic way to pass multiple columns toselect
/with_columns
/groupby
/... #6451 for examples.5. Newly added flags or experimental args should be keyword-only
to_dummies(separator)
(recent addition)Bonus. Arguments that do not match these criteria SHOULD NOT BE KEYWORD-ONLY.
join(other, on, how, *, left_on, right_on)
join(other, on=on, how=how)
. Let users decide their preferred syntax in this case (keyword or positional).Your input here is very welcome!
Changes
With this in mind, I made deprecation changes to the following functions/methods:
Next steps
There are definitely more to do. I figured I'd open this PR to run my 'philosphy' by you, and then do another pass with whatever strategy we come up with together.
I've also spotted quite a few parameter renaming opportunities, I'll do that next.
And then after that, I will do another PR where I remove the deprecations and apply the breaking changes. That can sit for a while until we go for
0.17.0
.