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 10 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/source/reference/testing.rst
Original file line number Diff line number Diff line change
@@ -51,6 +51,12 @@ Exceptions and warnings
errors.OptionError
errors.OutOfBoundsDatetime
errors.OutOfBoundsTimedelta
errors.PandasChangeWarning
errors.Pandas4Warning
errors.Pandas5Warning
errors.PandasPendingDeprecationWarning
errors.PandasDeprecationWarning
errors.PandasFutureWarning
errors.ParserError
errors.ParserWarning
errors.PerformanceWarning
12 changes: 12 additions & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
@@ -24,6 +24,18 @@ 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. This was done to give downstream packages more time to adjust to pandas deprecations, which should reduce the amount of warnings that a user gets from code that isn't theirs. See `PDEP 17 <https://pandas.pydata.org/pdeps/0017-backwards-compatibility-and-deprecation-policy.html>`_ for more details.

All warnings for upcoming changes in pandas will have the base class :class:`pandas.errors.PandasChangeWarning`. Users may also use the following subclasses to control warnings.

- :class:`pandas.errors.Pandas4Warning`: Warnings which will be enforced in pandas 4.0.
- :class:`pandas.errors.Pandas5Warning`: Warnings which will be enforced in pandas 5.0.
- :class:`pandas.errors.PandasPendingDeprecationWarning`: Base class of all warnings which emit a ``PendingDeprecationWarning``, independent of the version they will be enforced.
- :class:`pandas.errors.PandasDeprecationWarning`: Base class of all warnings which emit a ``DeprecationWarning``, independent of the version they will be enforced.
- :class:`pandas.errors.PandasFutureWarning`: Base class of all warnings which emit a ``PandasFutureWarning``, independent of the version they will be enforced.

.. _whatsnew_300.enhancements.other:

Other enhancements
8 changes: 6 additions & 2 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
@@ -1994,12 +1994,14 @@ class Timestamp(_Timestamp):
>>> pd.Timestamp.utcnow() # doctest: +SKIP
Timestamp('2020-11-16 22:50:18.092888+0000', tz='UTC')
"""
from pandas.errors import Pandas4Warning

warnings.warn(
# The stdlib datetime.utcnow is deprecated, so we deprecate to match.
# GH#56680
"Timestamp.utcnow is deprecated and will be removed in a future "
"version. Use Timestamp.now('UTC') instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return cls.now(UTC)
@@ -2036,13 +2038,15 @@ class Timestamp(_Timestamp):
>>> pd.Timestamp.utcfromtimestamp(1584199972)
Timestamp('2020-03-14 15:32:52+0000', tz='UTC')
"""
from pandas.errors import Pandas4Warning

# GH#22451
warnings.warn(
# The stdlib datetime.utcfromtimestamp is deprecated, so we deprecate
# to match. GH#56680
"Timestamp.utcfromtimestamp is deprecated and will be removed in a "
"future version. Use Timestamp.fromtimestamp(ts, 'UTC') instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return cls.fromtimestamp(ts, tz="UTC")
27 changes: 15 additions & 12 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
@@ -55,6 +55,7 @@
from pandas.errors import (
ChainedAssignmentError,
InvalidIndexError,
Pandas4Warning,
)
from pandas.errors.cow import (
_chained_assignment_method_msg,
@@ -11915,7 +11916,7 @@ def all(
**kwargs,
) -> Series | bool: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="all")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="all")
@doc(make_doc("all", ndim=1))
def all(
self,
@@ -11962,7 +11963,7 @@ def min(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="min")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="min")
@doc(make_doc("min", ndim=2))
def min(
self,
@@ -12009,7 +12010,7 @@ def max(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="max")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="max")
@doc(make_doc("max", ndim=2))
def max(
self,
@@ -12025,7 +12026,7 @@ def max(
result = result.__finalize__(self, method="max")
return result

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sum")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sum")
def sum(
self,
axis: Axis | None = 0,
@@ -12126,7 +12127,7 @@ def sum(
result = result.__finalize__(self, method="sum")
return result

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="prod")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="prod")
def prod(
self,
axis: Axis | None = 0,
@@ -12244,7 +12245,7 @@ def mean(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="mean")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="mean")
@doc(make_doc("mean", ndim=2))
def mean(
self,
@@ -12291,7 +12292,9 @@ def median(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="median")
@deprecate_nonkeyword_arguments(
Pandas4Warning, allowed_args=["self"], name="median"
)
@doc(make_doc("median", ndim=2))
def median(
self,
@@ -12341,7 +12344,7 @@ def sem(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sem")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sem")
def sem(
self,
axis: Axis | None = 0,
@@ -12461,7 +12464,7 @@ def var(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="var")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="var")
def var(
self,
axis: Axis | None = 0,
@@ -12580,7 +12583,7 @@ def std(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="std")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="std")
def std(
self,
axis: Axis | None = 0,
@@ -12703,7 +12706,7 @@ def skew(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="skew")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="skew")
def skew(
self,
axis: Axis | None = 0,
@@ -12823,7 +12826,7 @@ def kurt(
**kwargs,
) -> Series | Any: ...

@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="kurt")
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="kurt")
def kurt(
self,
axis: Axis | None = 0,
9 changes: 5 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@
AbstractMethodError,
ChainedAssignmentError,
InvalidIndexError,
Pandas4Warning,
)
from pandas.errors.cow import _chained_assignment_method_msg
from pandas.util._decorators import (
@@ -2594,15 +2595,15 @@ def to_json(
warnings.warn(
"The default 'epoch' date format is deprecated and will be removed "
"in a future version, please use 'iso' date format instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
elif date_format == "epoch":
# GH#57063
warnings.warn(
"'epoch' date format is deprecated and will be removed in a future "
"version, please use 'iso' date format instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)

@@ -4381,12 +4382,12 @@ def _check_copy_deprecation(copy):
"version. Copy-on-Write is active in pandas since 3.0 which utilizes "
"a lazy copy mechanism that defers copies until necessary. Use "
".copy() to make an eager copy if necessary.",
DeprecationWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)

# issue 58667
@deprecate_kwarg("method", None)
@deprecate_kwarg(Pandas4Warning, "method", new_arg_name=None)
@final
def reindex_like(
self,
7 changes: 5 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,10 @@

from pandas._libs import Interval
from pandas._libs.hashtable import duplicated
from pandas.errors import SpecificationError
from pandas.errors import (
Pandas4Warning,
SpecificationError,
)
from pandas.util._decorators import (
Appender,
Substitution,
@@ -3332,7 +3335,7 @@ def corrwith(
"""
warnings.warn(
"DataFrameGroupBy.corrwith is deprecated",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
result = self._op_via_apply(
5 changes: 3 additions & 2 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@
import numpy as np

from pandas._libs import lib
from pandas.errors import Pandas4Warning
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.common import (
@@ -218,7 +219,7 @@ def to_pytimedelta(self):
"in a future version this will return a Series containing python "
"datetime.timedelta objects instead of an ndarray. To retain the "
"old behavior, call `np.array` on the result",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta()
@@ -501,7 +502,7 @@ def to_pytimedelta(self) -> np.ndarray:
"in a future version this will return a Series containing python "
"datetime.timedelta objects instead of an ndarray. To retain the "
"old behavior, call `np.array` on the result",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return self._get_values().to_pytimedelta()
3 changes: 2 additions & 1 deletion pandas/core/internals/api.py
Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@
import numpy as np

from pandas._libs.internals import BlockPlacement
from pandas.errors import Pandas4Warning

from pandas.core.dtypes.common import pandas_dtype
from pandas.core.dtypes.dtypes import (
@@ -93,7 +94,7 @@ def make_block(
"make_block is deprecated and will be removed in a future version. "
"Use pd.api.internals.create_dataframe_from_blocks or "
"(recommended) higher-level public APIs instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)

3 changes: 2 additions & 1 deletion pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import numpy as np

from pandas._libs import lib
from pandas.errors import Pandas4Warning
from pandas.util._decorators import set_module
from pandas.util._exceptions import find_stack_level

@@ -392,7 +393,7 @@ def concat(
"version. Copy-on-Write is active in pandas since 3.0 which utilizes "
"a lazy copy mechanism that defers copies until necessary. Use "
".copy() to make an eager copy if necessary.",
DeprecationWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
if join == "outer":
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.