Skip to content

Commit 80edcb3

Browse files
Aloqeelyrhshadrach
authored andcommitted
ENH: Implement PDEP-17
1 parent c75171a commit 80edcb3

Some content is hidden

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

41 files changed

+350
-135
lines changed

doc/source/reference/testing.rst

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

doc/source/whatsnew/v3.0.0.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ 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.
30+
31+
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.
32+
2733
.. _whatsnew_300.enhancements.other:
2834

2935
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: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from pandas.errors import (
5656
ChainedAssignmentError,
5757
InvalidIndexError,
58+
Pandas4Warning,
5859
)
5960
from pandas.errors.cow import (
6061
_chained_assignment_method_msg,
@@ -11909,7 +11910,9 @@ def all(
1190911910
**kwargs,
1191011911
) -> Series | bool: ...
1191111912

11912-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="all")
11913+
@deprecate_nonkeyword_arguments(
11914+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="all"
11915+
)
1191311916
@doc(make_doc("all", ndim=1))
1191411917
def all(
1191511918
self,
@@ -11956,7 +11959,9 @@ def min(
1195611959
**kwargs,
1195711960
) -> Series | Any: ...
1195811961

11959-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="min")
11962+
@deprecate_nonkeyword_arguments(
11963+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="min"
11964+
)
1196011965
@doc(make_doc("min", ndim=2))
1196111966
def min(
1196211967
self,
@@ -12003,7 +12008,9 @@ def max(
1200312008
**kwargs,
1200412009
) -> Series | Any: ...
1200512010

12006-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="max")
12011+
@deprecate_nonkeyword_arguments(
12012+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="max"
12013+
)
1200712014
@doc(make_doc("max", ndim=2))
1200812015
def max(
1200912016
self,
@@ -12019,7 +12026,9 @@ def max(
1201912026
result = result.__finalize__(self, method="max")
1202012027
return result
1202112028

12022-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sum")
12029+
@deprecate_nonkeyword_arguments(
12030+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="sum"
12031+
)
1202312032
def sum(
1202412033
self,
1202512034
axis: Axis | None = 0,
@@ -12120,7 +12129,9 @@ def sum(
1212012129
result = result.__finalize__(self, method="sum")
1212112130
return result
1212212131

12123-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="prod")
12132+
@deprecate_nonkeyword_arguments(
12133+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="prod"
12134+
)
1212412135
def prod(
1212512136
self,
1212612137
axis: Axis | None = 0,
@@ -12238,7 +12249,9 @@ def mean(
1223812249
**kwargs,
1223912250
) -> Series | Any: ...
1224012251

12241-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="mean")
12252+
@deprecate_nonkeyword_arguments(
12253+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="mean"
12254+
)
1224212255
@doc(make_doc("mean", ndim=2))
1224312256
def mean(
1224412257
self,
@@ -12285,7 +12298,9 @@ def median(
1228512298
**kwargs,
1228612299
) -> Series | Any: ...
1228712300

12288-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="median")
12301+
@deprecate_nonkeyword_arguments(
12302+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="median"
12303+
)
1228912304
@doc(make_doc("median", ndim=2))
1229012305
def median(
1229112306
self,
@@ -12335,7 +12350,9 @@ def sem(
1233512350
**kwargs,
1233612351
) -> Series | Any: ...
1233712352

12338-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="sem")
12353+
@deprecate_nonkeyword_arguments(
12354+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="sem"
12355+
)
1233912356
def sem(
1234012357
self,
1234112358
axis: Axis | None = 0,
@@ -12455,7 +12472,9 @@ def var(
1245512472
**kwargs,
1245612473
) -> Series | Any: ...
1245712474

12458-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="var")
12475+
@deprecate_nonkeyword_arguments(
12476+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="var"
12477+
)
1245912478
def var(
1246012479
self,
1246112480
axis: Axis | None = 0,
@@ -12574,7 +12593,9 @@ def std(
1257412593
**kwargs,
1257512594
) -> Series | Any: ...
1257612595

12577-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="std")
12596+
@deprecate_nonkeyword_arguments(
12597+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="std"
12598+
)
1257812599
def std(
1257912600
self,
1258012601
axis: Axis | None = 0,
@@ -12697,7 +12718,9 @@ def skew(
1269712718
**kwargs,
1269812719
) -> Series | Any: ...
1269912720

12700-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="skew")
12721+
@deprecate_nonkeyword_arguments(
12722+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="skew"
12723+
)
1270112724
def skew(
1270212725
self,
1270312726
axis: Axis | None = 0,
@@ -12817,7 +12840,9 @@ def kurt(
1281712840
**kwargs,
1281812841
) -> Series | Any: ...
1281912842

12820-
@deprecate_nonkeyword_arguments(version="4.0", allowed_args=["self"], name="kurt")
12843+
@deprecate_nonkeyword_arguments(
12844+
version="4.0", klass=Pandas4Warning, allowed_args=["self"], name="kurt"
12845+
)
1282112846
def kurt(
1282212847
self,
1282312848
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 (
@@ -2594,15 +2595,15 @@ def to_json(
25942595
warnings.warn(
25952596
"The default 'epoch' date format is deprecated and will be removed "
25962597
"in a future version, please use 'iso' date format instead.",
2597-
FutureWarning,
2598+
Pandas4Warning,
25982599
stacklevel=find_stack_level(),
25992600
)
26002601
elif date_format == "epoch":
26012602
# GH#57063
26022603
warnings.warn(
26032604
"'epoch' date format is deprecated and will be removed in a future "
26042605
"version, please use 'iso' date format instead.",
2605-
FutureWarning,
2606+
Pandas4Warning,
26062607
stacklevel=find_stack_level(),
26072608
)
26082609

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

43884389
# issue 58667
4389-
@deprecate_kwarg("method", None)
4390+
@deprecate_kwarg("method", klass=Pandas4Warning, new_arg_name=None)
43904391
@final
43914392
def reindex_like(
43924393
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,
@@ -3330,7 +3333,7 @@ def corrwith(
33303333
"""
33313334
warnings.warn(
33323335
"DataFrameGroupBy.corrwith is deprecated",
3333-
FutureWarning,
3336+
Pandas4Warning,
33343337
stacklevel=find_stack_level(),
33353338
)
33363339
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 (
@@ -93,7 +94,7 @@ def make_block(
9394
"make_block is deprecated and will be removed in a future version. "
9495
"Use pd.api.internals.create_dataframe_from_blocks or "
9596
"(recommended) higher-level public APIs instead.",
96-
DeprecationWarning,
97+
Pandas4Warning,
9798
stacklevel=2,
9899
)
99100

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)