Skip to content

ENH: Implement PDEP-17 #61468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

rhshadrach
Copy link
Member

@rhshadrach rhshadrach commented May 20, 2025

  • closes #xxxx (Replace xxxx with the GitHub issue number)
  • Tests added and passed if fixing a bug or adding a new feature
  • All code checks passed.
  • Added type annotations to new arguments/methods/functions.
  • Added an entry in the latest doc/source/whatsnew/vX.X.X.rst file if fixing a bug or adding a new feature.

Continuation of #58169

Still needs tests and some cleanup with the docs and decorator arguments, but I'd like to get a first look.

cc @Dr-Irv @Aloqeely

Comment on lines 94 to 97
class PandasChangeWarning(Warning):
"""
Warning raised for any an upcoming change.
"""
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in love with this name, but PandasDeprecationWarning is taken below. Bikeshedding here is most welcome!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also make this internal if we want to not have it be public.

@rhshadrach rhshadrach added this to the 3.0 milestone May 20, 2025
@rhshadrach rhshadrach added Enhancement Warnings Warnings that appear or should be added to pandas PDEP pandas enhancement proposal labels May 20, 2025
@datapythonista datapythonista removed the PDEP pandas enhancement proposal label May 20, 2025
@datapythonista
Copy link
Member

Seems like the label PDEP can only be used for the PDEP themselves. Otherwise building the website fails, as it expects the PR to be a PDEP that needs to be rendered in the roadmap.

Copy link
Contributor

@Dr-Irv Dr-Irv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be separate docs about the deprecation policy and these classes, aside from what is in the whatsnew document.

@@ -24,6 +24,12 @@ Enhancement1
Enhancement2
^^^^^^^^^^^^

New Deprecation Policy
^^^^^^^^^^^^^^^^^^^^^^
pandas 3.0.0 introduces a new 3-stage deprecation policy: using ``DeprecationWarning`` initially, then switching to ``FutureWarning`` for broader visibility in the last minor version before the next major release, and then removal of the deprecated functionality in the major release.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we say that these could be tested via the classes PandasDeprecationWarning and PandasFutureWarning ?

Comment on lines +154 to +180
class Pandas4Warning(PandasDeprecationWarning):
"""
Warning raised for an upcoming change that will be enforced in pandas 4.0.

See Also
--------
errors.Pandas4Warning : Class for deprecations to be enforced in pandas 4.0.

Examples
--------
>>> pd.errors.Pandas4Warning
<class 'pandas.errors.Pandas4Warning'>
"""


class Pandas5Warning(PandasPendingDeprecationWarning):
"""
Warning raised for an upcoming change that will be enforced in pandas 5.0.

See Also
--------
errors.Pandas4Warning : Class for deprecations to be enforced in pandas 4.0.

Examples
--------
>>> pd.errors.Pandas5Warning
<class 'pandas.errors.Pandas5Warning'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should have an abstract base class PandasWarning that has an abstract class method version(), and then both Pandas4Warning and Pandas5Warning inherit from that class as well, and define version() to return 4 and 5 respectively.

Then in deprecate_nonkeyword_arguments(), instead of checking for the class, you just check for version(). See comment there.

Comment on lines +292 to +301
from pandas.errors import (
Pandas4Warning,
Pandas5Warning,
)

if klass is Pandas4Warning:
version = "4.0"
elif klass is Pandas5Warning:
version = "5.0"
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create the ABC PandasWarning as suggested above, then you could just do

    if issubclass(klass, PandasWarning):
        version = klass.version()
    else:
        raise AssertionError(f"{type(klass)=} must be a versioned warning")

@@ -51,6 +51,12 @@ Exceptions and warnings
errors.OptionError
errors.OutOfBoundsDatetime
errors.OutOfBoundsTimedelta
errors.PandasChangeWarning
errors.Pandas4Warning
errors.Pandas5Warning
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aside from the tests, Pandas5Warning isn't used. Is the idea that we will use it in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Warnings Warnings that appear or should be added to pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants