Skip to content

API: future.default_arg for method-specific behavior changes #60593

Open
@rhshadrach

Description

@rhshadrach

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 to no_default.
    • future=True gives the future behavior after the deprecation will be enforced.
    • future=False gives the current behavior, with no warning message.
    • future=no_default gives a warning message
  • Introduce a global underride future.default_arg = [True | False | no_default] defaulting to no_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 a future argument. When the future argument is specified in the function call itself, this value will not be used. When future.default_arg is not specified (so has value no_default), calling functions will warn on the upcoming change. When future.default_arg is set to True, the future behavior of functions will be used. When future.default_arg is set to False, the current behavior of functions will be used without warning. In particular, if you specify future.default_arg = False and upgrade across major versions of pandas, you will experience breaking changes without warning!

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDeprecateFunctionality to remove in pandasNeeds DiscussionRequires discussion from core team before further action

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions