-
-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Ref: #60551 (comment)
Whenever possible, a deprecation should be performed without the introduction of a new argument for performing said deprecation. However there are times where we are changing the behavior of an existing function or method where the output will change on the same set of input arguments. For this, I think pandas should have a standard way of modifying the existing behavior.
I think there are two common cases when using pandas:
- The code I write is short-lived and when I get something working on one version of pandas, that's the only version it needs to work on.
- The code I write is maintained, and I will need to upgrade pandas and have it still perform correctly.
I think we can support both use cases by:
- Any time a particular method behavior changes, introduce a keyword-only argument
future=[True | False | no_default]defaulting tono_default.future=Truegives the future behavior after the deprecation will be enforced.future=Falsegives the current behavior, with no warning message.future=no_defaultgives a warning message
- Introduce a global underride
future.default_arg = [True | False | no_default]defaulting tono_default.
When e.g. df.method(...) is called without specifying the value of future, only then will the value future.default_arg will be used.
Users can keep the current behavior and globally disable all warnings by specifying future.default_arg = False. If they were to do so and upgrade across major versions of pandas, they will see breaking changes without ever getting any warnings. As such, I think the documentation on this should read something like:
future.default_arg : bool | no_default
Global underride of any pandas function that has afutureargument. When thefutureargument is specified in the function call itself, this value will not be used. Whenfuture.default_argis not specified (so has valueno_default), calling functions will warn on the upcoming change. Whenfuture.default_argis set toTrue, the future behavior of functions will be used. Whenfuture.default_argis set toFalse, the current behavior of functions will be used without warning. In particular, if you specifyfuture.default_arg = Falseand upgrade across major versions of pandas, you will experience breaking changes without warning!