Deprecate non-keyword arguments for methods with inplace · Issue #41485 · pandas-dev/pandas (original) (raw)

Background

Having many parameters with defaults makes static typing a lot harder when one of them changes the return type, as they require many* overloads.

There's still no broad agreement about whether or not to deprecate the inplace argument, so in the meanwhile, if we force default-arguments to be keyword-only, then we can at least set the correct return types for these methods without requiring all these overloads (as many as 38 in one case!).

What to do

  1. Choose a method from the following list:
  1. Use pandas.util._decorators.deprecate_nonkeyword_arguments to issue a FutureWarning that the method's default arguments will be keyword-only in the next release.
  2. Fixup any tests / internal code which uses such default arguments positionally. See this gist for a helper-script which can help identify cases which need fixing, just replace "drop" with whatever method you're working on and then run it as python visitor.py.
  3. Add a new test, checking that a FutureWarning is raised if this method's default arguments are used positionally.
  4. Add a note to doc/source/whatsnew/v1.3.0.rst

See #41511 for an example of how to do this.

In most of these methods, the first argument is probably fine to be kept as is, it's the ones after that (such as axis) which should become keyword-only.


*(2^{number of default types preceding the one to overload} +2)


It's really common to call replace with both value and to_replace as positional, so I think we can make an exception for that one. It'll only require 6 overloads, which I'd argue isn't too many, especially if no other method requires more than 3 or 4


TODO: unify the whatsnew entries