Skip to content

Commit d1cbf9b

Browse files
rhshadrachAloqeelysimonjayhawkinsmroeschke
authored andcommitted
ENH: Implement PDEP-17 (pandas-dev#61468)
Co-authored-by: Abdulaziz Aloqeely <[email protected]> Co-authored-by: Simon Hawkins <[email protected]> Co-authored-by: Matthew Roeschke <[email protected]>
1 parent bfaa8d3 commit d1cbf9b

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,
@@ -12056,7 +12057,7 @@ def all(
1205612057
**kwargs,
1205712058
) -> Series | bool: ...
1205812059

12059-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="all")
12060+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="all")
1206012061
@doc(make_doc("all", ndim=1))
1206112062
def all(
1206212063
self,
@@ -12103,7 +12104,7 @@ def min(
1210312104
**kwargs,
1210412105
) -> Series | Any: ...
1210512106

12106-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="min")
12107+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="min")
1210712108
@doc(make_doc("min", ndim=2))
1210812109
def min(
1210912110
self,
@@ -12150,7 +12151,7 @@ def max(
1215012151
**kwargs,
1215112152
) -> Series | Any: ...
1215212153

12153-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="max")
12154+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="max")
1215412155
@doc(make_doc("max", ndim=2))
1215512156
def max(
1215612157
self,
@@ -12166,7 +12167,7 @@ def max(
1216612167
result = result.__finalize__(self, method="max")
1216712168
return result
1216812169

12169-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sum")
12170+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sum")
1217012171
def sum(
1217112172
self,
1217212173
axis: Axis | None = 0,
@@ -12267,7 +12268,7 @@ def sum(
1226712268
result = result.__finalize__(self, method="sum")
1226812269
return result
1226912270

12270-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="prod")
12271+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="prod")
1227112272
def prod(
1227212273
self,
1227312274
axis: Axis | None = 0,
@@ -12385,7 +12386,7 @@ def mean(
1238512386
**kwargs,
1238612387
) -> Series | Any: ...
1238712388

12388-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="mean")
12389+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="mean")
1238912390
@doc(make_doc("mean", ndim=2))
1239012391
def mean(
1239112392
self,
@@ -12432,7 +12433,9 @@ def median(
1243212433
**kwargs,
1243312434
) -> Series | Any: ...
1243412435

12435-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="median")
12436+
@deprecate_nonkeyword_arguments(
12437+
Pandas4Warning, allowed_args=["self"], name="median"
12438+
)
1243612439
@doc(make_doc("median", ndim=2))
1243712440
def median(
1243812441
self,
@@ -12482,7 +12485,7 @@ def sem(
1248212485
**kwargs,
1248312486
) -> Series | Any: ...
1248412487

12485-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sem")
12488+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="sem")
1248612489
def sem(
1248712490
self,
1248812491
axis: Axis | None = 0,
@@ -12602,7 +12605,7 @@ def var(
1260212605
**kwargs,
1260312606
) -> Series | Any: ...
1260412607

12605-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="var")
12608+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="var")
1260612609
def var(
1260712610
self,
1260812611
axis: Axis | None = 0,
@@ -12721,7 +12724,7 @@ def std(
1272112724
**kwargs,
1272212725
) -> Series | Any: ...
1272312726

12724-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="std")
12727+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="std")
1272512728
def std(
1272612729
self,
1272712730
axis: Axis | None = 0,
@@ -12844,7 +12847,7 @@ def skew(
1284412847
**kwargs,
1284512848
) -> Series | Any: ...
1284612849

12847-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="skew")
12850+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="skew")
1284812851
def skew(
1284912852
self,
1285012853
axis: Axis | None = 0,
@@ -12964,7 +12967,7 @@ def kurt(
1296412967
**kwargs,
1296512968
) -> Series | Any: ...
1296612969

12967-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="kurt")
12970+
@deprecate_nonkeyword_arguments(Pandas4Warning, allowed_args=["self"], name="kurt")
1296812971
def kurt(
1296912972
self,
1297012973
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)