Skip to content
Merged
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
10 changes: 8 additions & 2 deletions pandas/_libs/tslibs/offsets.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -5192,12 +5192,15 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
if name in _lite_rule_alias:
return name
if name in c_PERIOD_AND_OFFSET_DEPR_FREQSTR:
from pandas.errors import Pandas4Warning

# https://github.com/pandas-dev/pandas/pull/59240
warnings.warn(
f"\'{name}\' is deprecated and will be removed "
f"in a future version, please use "
f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\' "
f"instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return c_PERIOD_AND_OFFSET_DEPR_FREQSTR[name]
Expand All @@ -5206,12 +5209,15 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
if name == _name:
continue
if _name in c_PERIOD_AND_OFFSET_DEPR_FREQSTR.values():
from pandas.errors import Pandas4Warning

# https://github.com/pandas-dev/pandas/pull/59240
warnings.warn(
f"\'{name}\' is deprecated and will be removed "
f"in a future version, please use "
f"\'{_name}\' "
f"instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return _name
Expand Down
1 change: 1 addition & 0 deletions pandas/_libs/tslibs/period.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3018,6 +3018,7 @@ class Period(_Period):
# GH#53446
import warnings

# TODO: Enforce in 3.0 (#53511)
from pandas.util._exceptions import find_stack_level
warnings.warn(
"Period with BDay freq is deprecated and will be removed "
Expand Down
7 changes: 6 additions & 1 deletion pandas/_libs/tslibs/timedeltas.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ from pandas._libs.tslibs.np_datetime import (
)

from pandas._libs.tslibs.offsets cimport is_tick_object

from pandas._libs.tslibs.offsets import Day

from pandas._libs.tslibs.util cimport (
is_array,
is_float_object,
Expand Down Expand Up @@ -722,11 +724,14 @@ cpdef inline str parse_timedelta_unit(str unit):
elif unit == "M":
return unit
elif unit in c_DEPR_UNITS:
from pandas.errors import Pandas4Warning

# https://github.com/pandas-dev/pandas/pull/59240
warnings.warn(
f"\'{unit}\' is deprecated and will be removed in a "
f"future version. Please use \'{c_DEPR_UNITS.get(unit)}\' "
f"instead of \'{unit}\'.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
unit = c_DEPR_UNITS[unit]
Expand Down
3 changes: 2 additions & 1 deletion pandas/core/arrays/arrow/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
pa_version_under12p1,
pa_version_under13p0,
)
from pandas.errors import Pandas4Warning
from pandas.util._decorators import doc
from pandas.util._exceptions import find_stack_level

Expand Down Expand Up @@ -936,7 +937,7 @@ def _logical_method(self, other, op) -> Self:
f"'{op_name}' operations between boolean dtype and {self.dtype} are "
"deprecated and will raise in a future version. Explicitly "
"cast the strings to a boolean dtype before operating instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return op(other, self.astype(bool))
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
pa_version_under12p1,
)
from pandas.compat.numpy import function as nv
from pandas.errors import Pandas4Warning
from pandas.util._decorators import (
doc,
set_module,
Expand Down Expand Up @@ -167,6 +168,7 @@ def __init__(
storage = "python"

if storage == "pyarrow_numpy":
# TODO: Enforce in 3.0 (#60152)
warnings.warn(
"The 'pyarrow_numpy' storage option name is deprecated and will be "
'removed in pandas 3.0. Use \'pd.StringDtype(storage="pyarrow", '
Expand Down Expand Up @@ -400,7 +402,7 @@ def _logical_method(self, other, op):
f"'{op_name}' operations between boolean dtype and {self.dtype} are "
"deprecated and will raise in a future version. Explicitly "
"cast the strings to a boolean dtype before operating instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
return op(other, self.astype(bool))
Expand Down
1 change: 1 addition & 0 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ def insert(self, loc: int, item) -> ArrowStringArray:

def _convert_bool_result(self, values, na=lib.no_default, method_name=None):
if na is not lib.no_default and not isna(na) and not isinstance(na, bool):
# TODO: Enforce in 3.0 (#59615)
# GH#59561
warnings.warn(
f"Allowing a non-bool 'na' in obj.str.{method_name} is deprecated "
Expand Down
15 changes: 8 additions & 7 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
lib,
)
from pandas._libs.tslibs import conversion
from pandas.errors import Pandas4Warning
from pandas.util._exceptions import find_stack_level

from pandas.core.dtypes.base import _registry as registry
Expand Down Expand Up @@ -235,7 +236,7 @@ def is_sparse(arr) -> bool:
warnings.warn(
"is_sparse is deprecated and will be removed in a future "
"version. Check `isinstance(dtype, pd.SparseDtype)` instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)

Expand Down Expand Up @@ -370,7 +371,7 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
warnings.warn(
"is_datetime64tz_dtype is deprecated and will be removed in a future "
"version. Check `isinstance(dtype, pd.DatetimeTZDtype)` instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
if isinstance(arr_or_dtype, DatetimeTZDtype):
Expand Down Expand Up @@ -466,7 +467,7 @@ def is_period_dtype(arr_or_dtype) -> bool:
warnings.warn(
"is_period_dtype is deprecated and will be removed in a future version. "
"Use `isinstance(dtype, pd.PeriodDtype)` instead",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
Expand Down Expand Up @@ -524,7 +525,7 @@ def is_interval_dtype(arr_or_dtype) -> bool:
warnings.warn(
"is_interval_dtype is deprecated and will be removed in a future version. "
"Use `isinstance(dtype, pd.IntervalDtype)` instead",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
Expand Down Expand Up @@ -578,7 +579,7 @@ def is_categorical_dtype(arr_or_dtype) -> bool:
warnings.warn(
"is_categorical_dtype is deprecated and will be removed in a future "
"version. Use isinstance(dtype, pd.CategoricalDtype) instead",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
Expand Down Expand Up @@ -973,7 +974,7 @@ def is_int64_dtype(arr_or_dtype) -> bool:
warnings.warn(
"is_int64_dtype is deprecated and will be removed in a future "
"version. Use dtype == np.int64 instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
return _is_dtype_type(arr_or_dtype, classes(np.int64))
Expand Down Expand Up @@ -1436,7 +1437,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
"The behavior of is_bool_dtype with an object-dtype Index "
"of bool objects is deprecated. In a future version, "
"this will return False. Cast the Index to a bool dtype instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
return True
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ def __init__(
f"Passing a {type(data).__name__} to {type(self).__name__} "
"is deprecated and will raise in a future version. "
"Use public APIs instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)

Expand Down Expand Up @@ -9887,7 +9887,7 @@ def stack(
"removed in a future version of pandas. See the What's New notes "
"for pandas 2.1.0 for details. Do not specify the future_stack "
"argument to adopt the new implementation and silence this warning.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)

Expand Down
1 change: 1 addition & 0 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9133,6 +9133,7 @@ def resample(
from pandas.core.resample import get_resampler

if convention is not lib.no_default:
# TODO: Enforce in 3.0 (#55968)
warnings.warn(
f"The 'convention' keyword in {type(self).__name__}.resample is "
"deprecated and will be removed in a future version. "
Expand Down
8 changes: 5 additions & 3 deletions pandas/core/internals/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ def __getattr__(name: str):
# GH#55139
import warnings

from pandas.errors import Pandas4Warning

if name == "create_block_manager_from_blocks":
# GH#33892
# GH#33892, GH#58715
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
FutureWarning,
Pandas4Warning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
Expand All @@ -42,7 +44,7 @@ def __getattr__(name: str):
warnings.warn(
f"{name} is deprecated and will be removed in a future version. "
"Use public APIs instead.",
FutureWarning,
Pandas4Warning,
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
# on hard-coding stacklevel
stacklevel=2,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int
"""
warnings.warn(
"maybe_infer_ndim is deprecated and will be removed in a future version.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
return _maybe_infer_ndim(values, placement, ndim)
3 changes: 2 additions & 1 deletion pandas/core/internals/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pandas.errors import (
AbstractMethodError,
OutOfBoundsDatetime,
Pandas4Warning,
)
from pandas.util._decorators import cache_readonly
from pandas.util._exceptions import find_stack_level
Expand Down Expand Up @@ -1899,7 +1900,7 @@ def fillna(
"need to implement this keyword or an exception will be "
"raised. In the interim, the keyword is ignored by "
f"{type(self.values).__name__}.",
DeprecationWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)

Expand Down
1 change: 1 addition & 0 deletions pandas/core/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -1945,6 +1945,7 @@ class PeriodIndexResampler(DatetimeIndexResampler):

@property
def _resampler_for_grouping(self):
# TODO: Enforce in 3.0 (#55968)
warnings.warn(
"Resampling a groupby with a PeriodIndex is deprecated. "
"Cast to DatetimeIndex before resampling instead.",
Expand Down
9 changes: 5 additions & 4 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ def __init__(
f"Passing a {type(data).__name__} to {type(self).__name__} "
"is deprecated and will raise in a future version. "
"Use public APIs instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
data = data.copy(deep=False)
Expand All @@ -408,7 +408,7 @@ def __init__(
f"Passing a {type(data).__name__} to {type(self).__name__} "
"is deprecated and will raise in a future version. "
"Use public APIs instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)

Expand Down Expand Up @@ -477,7 +477,7 @@ def __init__(
f"Passing a {type(data).__name__} to {type(self).__name__} "
"is deprecated and will raise in a future version. "
"Use public APIs instead.",
DeprecationWarning,
Pandas4Warning,
stacklevel=2,
)
allow_mgr = True
Expand Down Expand Up @@ -4432,10 +4432,11 @@ def map(
if "arg" in kwargs:
# `.map(arg=my_func)`
func = kwargs.pop("arg")
# https://github.com/pandas-dev/pandas/pull/61264
warnings.warn(
"The parameter `arg` has been renamed to `func`, and it "
"will stop being supported in a future version of pandas.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
else:
Expand Down
3 changes: 2 additions & 1 deletion pandas/io/stata.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from pandas.errors import (
CategoricalConversionWarning,
InvalidColumnName,
Pandas4Warning,
PossiblePrecisionLoss,
ValueLabelTypeMismatch,
)
Expand Down Expand Up @@ -398,7 +399,7 @@ def parse_dates_safe(
"Converting object-dtype columns of datetimes to datetime64 when "
"writing to stata is deprecated. Call "
"`df=df.infer_objects(copy=False)` before writing to stata instead.",
FutureWarning,
Pandas4Warning,
stacklevel=find_stack_level(),
)
if delta:
Expand Down
5 changes: 3 additions & 2 deletions pandas/tests/arrays/test_datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import pytest

from pandas._libs.tslibs import tz_compare
from pandas.errors import Pandas4Warning

from pandas.core.dtypes.dtypes import DatetimeTZDtype

Expand Down Expand Up @@ -775,7 +776,7 @@ def test_date_range_uppercase_frequency_deprecated(self, freq_depr):
)

expected = pd.date_range("1/1/2000", periods=4, freq=freq_depr.lower())
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with tm.assert_produces_warning(Pandas4Warning, match=depr_msg):
result = pd.date_range("1/1/2000", periods=4, freq=freq_depr)
tm.assert_index_equal(result, expected)

Expand Down Expand Up @@ -804,7 +805,7 @@ def test_date_range_lowercase_frequency_deprecated(self):
depr_msg = "'w' is deprecated and will be removed in a future version"

expected = pd.date_range("1/1/2000", periods=4, freq="2W")
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
with tm.assert_produces_warning(Pandas4Warning, match=depr_msg):
result = pd.date_range("1/1/2000", periods=4, freq="2w")
tm.assert_index_equal(result, expected)

Expand Down
Loading
Loading