Skip to content
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

ENH: New proposed deprecation policy #58169

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
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/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Member

Choose a reason for hiding this comment

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

It might be good to add some reasoning to this
(e.g. This was done to give downstream packages more time to adjust to pandas deprecations, which should reducing the amount of warnings that an user gets from code that isn't theirs.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we'd have to also say that there would always be a minimal amount of time (6 months, maybe more??) between the last minor version before the next major release.

Copy link
Member Author

Choose a reason for hiding this comment

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

a minimal amount of time (6 months, maybe more??) between the last minor version before the next major release.

Is this consistent? 3.0 was planned to be released within 6 months of releasing 2.2.0 (#57064)

Copy link
Contributor

Choose a reason for hiding this comment

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

a minimal amount of time (6 months, maybe more??) between the last minor version before the next major release.

Is this consistent? 3.0 was planned to be released within 6 months of releasing 2.2.0 (#57064)

In your last commit, you wrote "This was done to give downstream packages more time to adjust to pandas deprecations". So if we are going to have a policy about this, then we have to decide how much time is sufficient for "more time".


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.

.. _whatsnew_300.enhancements.other:

Other enhancements
Expand Down
9 changes: 6 additions & 3 deletions pandas/_libs/tslibs/timestamps.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ import datetime as dt
from pandas._libs.tslibs cimport ccalendar
from pandas._libs.tslibs.base cimport ABCTimestamp

from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)

from pandas._libs.tslibs.conversion cimport (
_TSObject,
Expand Down Expand Up @@ -1533,7 +1536,7 @@ class Timestamp(_Timestamp):
# GH#56680
"Timestamp.utcnow is deprecated and will be removed in a future "
"version. Use Timestamp.now('UTC') instead.",
FutureWarning,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)
return cls.now(UTC)
Expand Down Expand Up @@ -1561,7 +1564,7 @@ class Timestamp(_Timestamp):
# to match. GH#56680
"Timestamp.utcfromtimestamp is deprecated and will be removed in a "
"future version. Use Timestamp.fromtimestamp(ts, 'UTC') instead.",
FutureWarning,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)
return cls.fromtimestamp(ts, tz="UTC")
Expand Down
11 changes: 7 additions & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@
deprecate_kwarg,
doc,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)
from pandas.util._validators import (
check_dtype_backend,
validate_ascending,
Expand Down Expand Up @@ -2570,15 +2573,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,
Pandas4DeprecationWarning,
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,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)

Expand Down Expand Up @@ -4306,7 +4309,7 @@ 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,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)

Expand Down
7 changes: 5 additions & 2 deletions pandas/core/groupby/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
Substitution,
doc,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)

from pandas.core.dtypes.common import (
ensure_int64,
Expand Down Expand Up @@ -2791,7 +2794,7 @@ def corrwith(
"""
warnings.warn(
"DataFrameGroupBy.corrwith is deprecated",
FutureWarning,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)
result = self._op_via_apply(
Expand Down
9 changes: 6 additions & 3 deletions pandas/core/indexes/accessors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import numpy as np

from pandas._libs import lib
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)

from pandas.core.dtypes.common import (
is_integer_dtype,
Expand Down Expand Up @@ -218,7 +221,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,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)
return cast(ArrowExtensionArray, self._parent.array)._dt_to_pytimedelta()
Expand Down Expand Up @@ -479,7 +482,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,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)
return self._get_values().to_pytimedelta()
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/internals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import numpy as np

from pandas._libs.internals import BlockPlacement
from pandas.util._exceptions import Pandas4DeprecationWarning

from pandas.core.dtypes.common import pandas_dtype
from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -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,
Pandas4DeprecationWarning,
stacklevel=2,
)

Expand Down
7 changes: 5 additions & 2 deletions pandas/core/reshape/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

from pandas._libs import lib
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)

from pandas.core.dtypes.common import is_bool
from pandas.core.dtypes.concat import concat_compat
Expand Down Expand Up @@ -382,7 +385,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,
Pandas4DeprecationWarning,
stacklevel=find_stack_level(),
)

Expand Down
3 changes: 2 additions & 1 deletion pandas/io/feather_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pandas._libs import lib
from pandas.compat._optional import import_optional_dependency
from pandas.util._decorators import doc
from pandas.util._exceptions import Pandas4DeprecationWarning
from pandas.util._validators import check_dtype_backend

import pandas as pd
Expand Down Expand Up @@ -136,7 +137,7 @@ def read_feather(
warnings.filterwarnings(
"ignore",
"make_block is deprecated",
DeprecationWarning,
Pandas4DeprecationWarning,
)

return feather.read_feather(
Expand Down
5 changes: 3 additions & 2 deletions pandas/io/parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from pandas.compat._optional import import_optional_dependency
from pandas.errors import AbstractMethodError
from pandas.util._decorators import doc
from pandas.util._exceptions import Pandas4DeprecationWarning
from pandas.util._validators import check_dtype_backend

import pandas as pd
Expand Down Expand Up @@ -278,7 +279,7 @@ def read(
filterwarnings(
"ignore",
"make_block is deprecated",
DeprecationWarning,
Pandas4DeprecationWarning,
)
result = pa_table.to_pandas(**to_pandas_kwargs)

Expand Down Expand Up @@ -397,7 +398,7 @@ def read(
filterwarnings(
"ignore",
"make_block is deprecated",
DeprecationWarning,
Pandas4DeprecationWarning,
)
return parquet_file.to_pandas(
columns=columns, filters=filters, **kwargs
Expand Down
7 changes: 5 additions & 2 deletions pandas/io/parsers/arrow_parser_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
ParserError,
ParserWarning,
)
from pandas.util._exceptions import find_stack_level
from pandas.util._exceptions import (
Pandas4DeprecationWarning,
find_stack_level,
)

from pandas.core.dtypes.common import pandas_dtype
from pandas.core.dtypes.inference import is_integer
Expand Down Expand Up @@ -291,7 +294,7 @@ def read(self) -> DataFrame:
warnings.filterwarnings(
"ignore",
"make_block is deprecated",
DeprecationWarning,
Pandas4DeprecationWarning,
)
if dtype_backend == "pyarrow":
frame = table.to_pandas(types_mapper=pd.ArrowDtype)
Expand Down
20 changes: 11 additions & 9 deletions pandas/tests/copy_view/test_copy_deprecation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from pandas.util._exceptions import Pandas4DeprecationWarning

import pandas as pd
from pandas import (
concat,
Expand Down Expand Up @@ -38,34 +40,34 @@ def test_copy_deprecation(meth, kwargs):
df = df.set_index(["b", "c"])

if meth != "swaplevel":
with tm.assert_produces_warning(DeprecationWarning, match="copy"):
with tm.assert_produces_warning(Pandas4DeprecationWarning, match="copy"):
getattr(df, meth)(copy=False, **kwargs)

if meth != "transpose":
with tm.assert_produces_warning(DeprecationWarning, match="copy"):
with tm.assert_produces_warning(Pandas4DeprecationWarning, match="copy"):
getattr(df.a, meth)(copy=False, **kwargs)


def test_copy_deprecation_reindex_like_align():
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
# Somehow the stack level check is incorrect here
with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
df.reindex_like(df, copy=False)

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
df.a.reindex_like(df.a, copy=False)

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
df.align(df, copy=False)

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
df.a.align(df.a, copy=False)

Expand All @@ -74,16 +76,16 @@ def test_copy_deprecation_merge_concat():
df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
df.merge(df, copy=False)

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
merge(df, df, copy=False)

with tm.assert_produces_warning(
DeprecationWarning, match="copy", check_stacklevel=False
Pandas4DeprecationWarning, match="copy", check_stacklevel=False
):
concat([df, df], copy=False)
5 changes: 3 additions & 2 deletions pandas/tests/extension/test_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
pa_version_under13p0,
pa_version_under14p0,
)
from pandas.util._exceptions import Pandas4DeprecationWarning
import pandas.util._test_decorators as td

from pandas.core.dtypes.dtypes import (
Expand Down Expand Up @@ -2862,14 +2863,14 @@ def test_dt_to_pytimedelta():
ser = pd.Series(data, dtype=ArrowDtype(pa.duration("ns")))

msg = "The behavior of ArrowTemporalProperties.to_pytimedelta is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas4DeprecationWarning, match=msg):
result = ser.dt.to_pytimedelta()
expected = np.array(data, dtype=object)
tm.assert_numpy_array_equal(result, expected)
assert all(type(res) is timedelta for res in result)

msg = "The behavior of TimedeltaProperties.to_pytimedelta is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(Pandas4DeprecationWarning, match=msg):
expected = ser.astype("timedelta64[ns]").dt.to_pytimedelta()
tm.assert_numpy_array_equal(result, expected)

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/frame/methods/test_reindex_like.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas4DeprecationWarning

from pandas import DataFrame
import pandas._testing as tm

Expand All @@ -22,10 +24,10 @@ def test_reindex_like(self, float_frame):
def test_reindex_like_methods(self, method, expected_values):
df = DataFrame({"x": list(range(5))})

with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(Pandas4DeprecationWarning):
result = df.reindex_like(df, method=method, tolerance=0)
tm.assert_frame_equal(df, result)
with tm.assert_produces_warning(FutureWarning):
with tm.assert_produces_warning(Pandas4DeprecationWarning):
result = df.reindex_like(df, method=method, tolerance=[0, 0, 0, 0])
tm.assert_frame_equal(df, result)

Expand Down
6 changes: 4 additions & 2 deletions pandas/tests/groupby/test_all_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import pytest

from pandas.util._exceptions import Pandas4DeprecationWarning

import pandas as pd
from pandas import DataFrame
import pandas._testing as tm
Expand All @@ -26,7 +28,7 @@ def test_multiindex_group_all_columns_when_empty(groupby_func):
method = getattr(gb, groupby_func)
args = get_groupby_method_args(groupby_func, df)
if groupby_func == "corrwith":
warn = FutureWarning
warn = Pandas4DeprecationWarning
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
else:
warn = None
Expand Down Expand Up @@ -72,7 +74,7 @@ def test_dup_labels_output_shape(groupby_func, idx):

args = get_groupby_method_args(groupby_func, df)
if groupby_func == "corrwith":
warn = FutureWarning
warn = Pandas4DeprecationWarning
warn_msg = "DataFrameGroupBy.corrwith is deprecated"
else:
warn = None
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import numpy as np
import pytest

from pandas.util._exceptions import Pandas4DeprecationWarning

import pandas as pd
from pandas import (
DataFrame,
Expand Down Expand Up @@ -1198,7 +1200,7 @@ def test_apply_is_unchanged_when_other_methods_are_called_first(reduction_func):
grp = df.groupby(by="a")
args = get_groupby_method_args(reduction_func, df)
if reduction_func == "corrwith":
warn = FutureWarning
warn = Pandas4DeprecationWarning
msg = "DataFrameGroupBy.corrwith is deprecated"
else:
warn = None
Expand Down
Loading
Loading