Skip to content

Commit 9597c03

Browse files
rhshadrachAloqeelysimonjayhawkinsmroeschke
authored
ENH: Implement PDEP-17 (#61468)
Co-authored-by: Abdulaziz Aloqeely <[email protected]> Co-authored-by: Simon Hawkins <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent d42575f commit 9597c03

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+477
-166
lines changed

doc/source/reference/testing.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ Exceptions and warnings
5252
errors.OptionError
5353
errors.OutOfBoundsDatetime
5454
errors.OutOfBoundsTimedelta
55+
errors.PandasChangeWarning
56+
errors.Pandas4Warning
57+
errors.Pandas5Warning
58+
errors.PandasPendingDeprecationWarning
59+
errors.PandasDeprecationWarning
60+
errors.PandasFutureWarning
5561
errors.ParserError
5662
errors.ParserWarning
5763
errors.PerformanceWarning

doc/source/whatsnew/v0.23.0.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ Please note that the string ``index`` is not supported with the round trip forma
105105
.. ipython:: python
106106
:okwarning:
107107
108+
df = pd.DataFrame(
109+
{
110+
'foo': [1, 2, 3, 4],
111+
'bar': ['a', 'b', 'c', 'd'],
112+
'baz': pd.date_range('2018-01-01', freq='d', periods=4),
113+
'qux': pd.Categorical(['a', 'b', 'c', 'c'])
114+
},
115+
index=pd.Index(range(4), name='idx')
116+
)
117+
108118
df.index.name = 'index'
109119
110120
df.to_json('test.json', orient='table')

doc/source/whatsnew/v3.0.0.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ Enhancement1
2424
Enhancement2
2525
^^^^^^^^^^^^
2626

27+
New Deprecation Policy
28+
^^^^^^^^^^^^^^^^^^^^^^
29+
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.
30+
31+
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.
32+
33+
- :class:`pandas.errors.Pandas4Warning`: Warnings which will be enforced in pandas 4.0.
34+
- :class:`pandas.errors.Pandas5Warning`: Warnings which will be enforced in pandas 5.0.
35+
- :class:`pandas.errors.PandasPendingDeprecationWarning`: Base class of all warnings which emit a ``PendingDeprecationWarning``, independent of the version they will be enforced.
36+
- :class:`pandas.errors.PandasDeprecationWarning`: Base class of all warnings which emit a ``DeprecationWarning``, independent of the version they will be enforced.
37+
- :class:`pandas.errors.PandasFutureWarning`: Base class of all warnings which emit a ``FutureWarning``, independent of the version they will be enforced.
38+
2739
.. _whatsnew_300.enhancements.other:
2840

2941
Other enhancements

pandas/_libs/tslibs/timestamps.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,12 +1994,14 @@ class Timestamp(_Timestamp):
19941994
>>> pd.Timestamp.utcnow() # doctest: +SKIP
19951995
Timestamp('2020-11-16 22:50:18.092888+0000', tz='UTC')
19961996
"""
1997+
from pandas.errors import Pandas4Warning
1998+
19971999
warnings.warn(
19982000
# The stdlib datetime.utcnow is deprecated, so we deprecate to match.
19992001
# GH#56680
20002002
"Timestamp.utcnow is deprecated and will be removed in a future "
20012003
"version. Use Timestamp.now('UTC') instead.",
2002-
FutureWarning,
2004+
Pandas4Warning,
20032005
stacklevel=find_stack_level(),
20042006
)
20052007
return cls.now(UTC)
@@ -2036,13 +2038,15 @@ class Timestamp(_Timestamp):
20362038
>>> pd.Timestamp.utcfromtimestamp(1584199972)
20372039
Timestamp('2020-03-14 15:32:52+0000', tz='UTC')
20382040
"""
2041+
from pandas.errors import Pandas4Warning
2042+
20392043
# GH#22451
20402044
warnings.warn(
20412045
# The stdlib datetime.utcfromtimestamp is deprecated, so we deprecate
20422046
# to match. GH#56680
20432047
"Timestamp.utcfromtimestamp is deprecated and will be removed in a "
20442048
"future version. Use Timestamp.fromtimestamp(ts, 'UTC') instead.",
2045-
FutureWarning,
2049+
Pandas4Warning,
20462050
stacklevel=find_stack_level(),
20472051
)
20482052
return cls.fromtimestamp(ts, tz="UTC")

pandas/core/frame.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from pandas.errors import (
5757
ChainedAssignmentError,
5858
InvalidIndexError,
59+
Pandas4Warning,
5960
)
6061
from pandas.errors.cow import (
6162
_chained_assignment_method_msg,
@@ -12061,7 +12062,7 @@ def all(
1206112062
**kwargs,
1206212063
) -> Series | bool: ...
1206312064

12064-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="all")
12065+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="all")
1206512066
@doc(make_doc("all", ndim=1))
1206612067
def all(
1206712068
self,
@@ -12108,7 +12109,7 @@ def min(
1210812109
**kwargs,
1210912110
) -> Series | Any: ...
1211012111

12111-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="min")
12112+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="min")
1211212113
@doc(make_doc("min", ndim=2))
1211312114
def min(
1211412115
self,
@@ -12155,7 +12156,7 @@ def max(
1215512156
**kwargs,
1215612157
) -> Series | Any: ...
1215712158

12158-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="max")
12159+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="max")
1215912160
@doc(make_doc("max", ndim=2))
1216012161
def max(
1216112162
self,
@@ -12171,7 +12172,7 @@ def max(
1217112172
result = result.__finalize__(self, method="max")
1217212173
return result
1217312174

12174-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sum")
12175+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sum")
1217512176
def sum(
1217612177
self,
1217712178
axis: Axis | None = 0,
@@ -12272,7 +12273,7 @@ def sum(
1227212273
result = result.__finalize__(self, method="sum")
1227312274
return result
1227412275

12275-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="prod")
12276+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="prod")
1227612277
def prod(
1227712278
self,
1227812279
axis: Axis | None = 0,
@@ -12390,7 +12391,7 @@ def mean(
1239012391
**kwargs,
1239112392
) -> Series | Any: ...
1239212393

12393-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="mean")
12394+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="mean")
1239412395
@doc(make_doc("mean", ndim=2))
1239512396
def mean(
1239612397
self,
@@ -12437,7 +12438,9 @@ def median(
1243712438
**kwargs,
1243812439
) -> Series | Any: ...
1243912440

12440-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="median")
12441+
@deprecate_nonkeyword_arguments(
12442+
Pandas4Warning, allowed_args=["self"], name="median"
12443+
)
1244112444
@doc(make_doc("median", ndim=2))
1244212445
def median(
1244312446
self,
@@ -12487,7 +12490,7 @@ def sem(
1248712490
**kwargs,
1248812491
) -> Series | Any: ...
1248912492

12490-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sem")
12493+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sem")
1249112494
def sem(
1249212495
self,
1249312496
axis: Axis | None = 0,
@@ -12607,7 +12610,7 @@ def var(
1260712610
**kwargs,
1260812611
) -> Series | Any: ...
1260912612

12610-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="var")
12613+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="var")
1261112614
def var(
1261212615
self,
1261312616
axis: Axis | None = 0,
@@ -12726,7 +12729,7 @@ def std(
1272612729
**kwargs,
1272712730
) -> Series | Any: ...
1272812731

12729-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="std")
12732+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="std")
1273012733
def std(
1273112734
self,
1273212735
axis: Axis | None = 0,
@@ -12849,7 +12852,7 @@ def skew(
1284912852
**kwargs,
1285012853
) -> Series | Any: ...
1285112854

12852-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="skew")
12855+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="skew")
1285312856
def skew(
1285412857
self,
1285512858
axis: Axis | None = 0,
@@ -12969,7 +12972,7 @@ def kurt(
1296912972
**kwargs,
1297012973
) -> Series | Any: ...
1297112974

12972-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="kurt")
12975+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="kurt")
1297312976
def kurt(
1297412977
self,
1297512978
axis: Axis | None = 0,

pandas/core/generic.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
AbstractMethodError,
9191
ChainedAssignmentError,
9292
InvalidIndexError,
93+
Pandas4Warning,
9394
)
9495
from pandas.errors.cow import _chained_assignment_method_msg
9596
from pandas.util._decorators import (
@@ -2589,15 +2590,15 @@ def to_json(
25892590
warnings.warn(
25902591
"The default 'epoch' date format is deprecated and will be removed "
25912592
"in a future version, please use 'iso' date format instead.",
2592-
FutureWarning,
2593+
Pandas4Warning,
25932594
stacklevel=find_stack_level(),
25942595
)
25952596
elif date_format == "epoch":
25962597
# GH#57063
25972598
warnings.warn(
25982599
"'epoch' date format is deprecated and will be removed in a future "
25992600
"version, please use 'iso' date format instead.",
2600-
FutureWarning,
2601+
Pandas4Warning,
26012602
stacklevel=find_stack_level(),
26022603
)
26032604

@@ -4376,12 +4377,12 @@ def _check_copy_deprecation(copy):
43764377
"version. Copy-on-Write is active in pandas since 3.0 which utilizes "
43774378
"a lazy copy mechanism that defers copies until necessary. Use "
43784379
".copy() to make an eager copy if necessary.",
4379-
DeprecationWarning,
4380+
Pandas4Warning,
43804381
stacklevel=find_stack_level(),
43814382
)
43824383

43834384
# issue 58667
4384-
@deprecate_kwarg("method", None)
4385+
@deprecate_kwarg(Pandas4Warning, "method", new_arg_name=None)
43854386
@final
43864387
def reindex_like(
43874388
self,

pandas/core/groupby/generic.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
from pandas._libs import Interval
2929
from pandas._libs.hashtable import duplicated
30-
from pandas.errors import SpecificationError
30+
from pandas.errors import (
31+
Pandas4Warning,
32+
SpecificationError,
33+
)
3134
from pandas.util._decorators import (
3235
Appender,
3336
Substitution,
@@ -3364,7 +3367,7 @@ def corrwith(
33643367
"""
33653368
warnings.warn(
33663369
"DataFrameGroupBy.corrwith is deprecated",
3367-
FutureWarning,
3370+
Pandas4Warning,
33683371
stacklevel=find_stack_level(),
33693372
)
33703373
result = self._op_via_apply(

pandas/core/indexes/accessors.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy as np
1515

1616
from pandas._libs import lib
17+
from pandas.errors import Pandas4Warning
1718
from pandas.util._exceptions import find_stack_level
1819

1920
from pandas.core.dtypes.common import (
@@ -218,7 +219,7 @@ def to_pytimedelta(self):
218219
"in a future version this will return a Series containing python "
219220
"datetime.timedelta objects instead of an ndarray. To retain the "
220221
"old behavior, call `np.array` on the result",
221-
FutureWarning,
222+
Pandas4Warning,
222223
stacklevel=find_stack_level(),
223224
)
224225
return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta()
@@ -501,7 +502,7 @@ def to_pytimedelta(self) -> np.ndarray:
501502
"in a future version this will return a Series containing python "
502503
"datetime.timedelta objects instead of an ndarray. To retain the "
503504
"old behavior, call `np.array` on the result",
504-
FutureWarning,
505+
Pandas4Warning,
505506
stacklevel=find_stack_level(),
506507
)
507508
return self._get_values().to_pytimedelta()

pandas/core/internals/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import numpy as np
1616

1717
from pandas._libs.internals import BlockPlacement
18+
from pandas.errors import Pandas4Warning
1819

1920
from pandas.core.dtypes.common import pandas_dtype
2021
from pandas.core.dtypes.dtypes import (
@@ -102,7 +103,7 @@ def make_block(
102103
"make_block is deprecated and will be removed in a future version. "
103104
"Use pd.api.internals.create_dataframe_from_blocks or "
104105
"(recommended) higher-level public APIs instead.",
105-
DeprecationWarning,
106+
Pandas4Warning,
106107
stacklevel=2,
107108
)
108109

pandas/core/reshape/concat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import numpy as np
1818

1919
from pandas._libs import lib
20+
from pandas.errors import Pandas4Warning
2021
from pandas.util._decorators import set_module
2122
from pandas.util._exceptions import find_stack_level
2223

@@ -392,7 +393,7 @@ def concat(
392393
"version. Copy-on-Write is active in pandas since 3.0 which utilizes "
393394
"a lazy copy mechanism that defers copies until necessary. Use "
394395
".copy() to make an eager copy if necessary.",
395-
DeprecationWarning,
396+
Pandas4Warning,
396397
stacklevel=find_stack_level(),
397398
)
398399
if join == "outer":

0 commit comments

Comments
 (0)