Skip to content

Commit 594889e

Browse files
authored
CLN: Replace warnings with Pandas4Warning (#62162)
1 parent 8129607 commit 594889e

Some content is hidden

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

47 files changed

+167
-85
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,12 +5192,15 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
51925192
if name in _lite_rule_alias:
51935193
return name
51945194
if name in c_PERIOD_AND_OFFSET_DEPR_FREQSTR:
5195+
from pandas.errors import Pandas4Warning
5196+
5197+
# https://github.com/pandas-dev/pandas/pull/59240
51955198
warnings.warn(
51965199
f"\'{name}\' is deprecated and will be removed "
51975200
f"in a future version, please use "
51985201
f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\' "
51995202
f"instead.",
5200-
FutureWarning,
5203+
Pandas4Warning,
52015204
stacklevel=find_stack_level(),
52025205
)
52035206
return c_PERIOD_AND_OFFSET_DEPR_FREQSTR[name]
@@ -5206,12 +5209,15 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
52065209
if name == _name:
52075210
continue
52085211
if _name in c_PERIOD_AND_OFFSET_DEPR_FREQSTR.values():
5212+
from pandas.errors import Pandas4Warning
5213+
5214+
# https://github.com/pandas-dev/pandas/pull/59240
52095215
warnings.warn(
52105216
f"\'{name}\' is deprecated and will be removed "
52115217
f"in a future version, please use "
52125218
f"\'{_name}\' "
52135219
f"instead.",
5214-
FutureWarning,
5220+
Pandas4Warning,
52155221
stacklevel=find_stack_level(),
52165222
)
52175223
return _name

pandas/_libs/tslibs/period.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3018,6 +3018,7 @@ class Period(_Period):
30183018
# GH#53446
30193019
import warnings
30203020

3021+
# TODO: Enforce in 3.0 (#53511)
30213022
from pandas.util._exceptions import find_stack_level
30223023
warnings.warn(
30233024
"Period with BDay freq is deprecated and will be removed "

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ from pandas._libs.tslibs.np_datetime import (
7878
)
7979

8080
from pandas._libs.tslibs.offsets cimport is_tick_object
81+
8182
from pandas._libs.tslibs.offsets import Day
83+
8284
from pandas._libs.tslibs.util cimport (
8385
is_array,
8486
is_float_object,
@@ -722,11 +724,14 @@ cpdef inline str parse_timedelta_unit(str unit):
722724
elif unit == "M":
723725
return unit
724726
elif unit in c_DEPR_UNITS:
727+
from pandas.errors import Pandas4Warning
728+
729+
# https://github.com/pandas-dev/pandas/pull/59240
725730
warnings.warn(
726731
f"\'{unit}\' is deprecated and will be removed in a "
727732
f"future version. Please use \'{c_DEPR_UNITS.get(unit)}\' "
728733
f"instead of \'{unit}\'.",
729-
FutureWarning,
734+
Pandas4Warning,
730735
stacklevel=find_stack_level(),
731736
)
732737
unit = c_DEPR_UNITS[unit]

pandas/core/arrays/arrow/array.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
pa_version_under12p1,
2929
pa_version_under13p0,
3030
)
31+
from pandas.errors import Pandas4Warning
3132
from pandas.util._decorators import doc
3233
from pandas.util._exceptions import find_stack_level
3334

@@ -943,7 +944,7 @@ def _logical_method(self, other, op) -> Self:
943944
f"'{op_name}' operations between boolean dtype and {self.dtype} are "
944945
"deprecated and will raise in a future version. Explicitly "
945946
"cast the strings to a boolean dtype before operating instead.",
946-
FutureWarning,
947+
Pandas4Warning,
947948
stacklevel=find_stack_level(),
948949
)
949950
return op(other, self.astype(bool))

pandas/core/arrays/string_.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
pa_version_under12p1,
3030
)
3131
from pandas.compat.numpy import function as nv
32+
from pandas.errors import Pandas4Warning
3233
from pandas.util._decorators import (
3334
doc,
3435
set_module,
@@ -167,6 +168,7 @@ def __init__(
167168
storage = "python"
168169

169170
if storage == "pyarrow_numpy":
171+
# TODO: Enforce in 3.0 (#60152)
170172
warnings.warn(
171173
"The 'pyarrow_numpy' storage option name is deprecated and will be "
172174
'removed in pandas 3.0. Use \'pd.StringDtype(storage="pyarrow", '
@@ -392,7 +394,7 @@ def _logical_method(self, other, op):
392394
f"'{op_name}' operations between boolean dtype and {self.dtype} are "
393395
"deprecated and will raise in a future version. Explicitly "
394396
"cast the strings to a boolean dtype before operating instead.",
395-
FutureWarning,
397+
Pandas4Warning,
396398
stacklevel=find_stack_level(),
397399
)
398400
return op(other, self.astype(bool))

pandas/core/arrays/string_arrow.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def insert(self, loc: int, item) -> ArrowStringArray:
240240

241241
def _convert_bool_result(self, values, na=lib.no_default, method_name=None):
242242
if na is not lib.no_default and not isna(na) and not isinstance(na, bool):
243+
# TODO: Enforce in 3.0 (#59615)
243244
# GH#59561
244245
warnings.warn(
245246
f"Allowing a non-bool 'na' in obj.str.{method_name} is deprecated "

pandas/core/dtypes/common.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
lib,
2222
)
2323
from pandas._libs.tslibs import conversion
24+
from pandas.errors import Pandas4Warning
2425
from pandas.util._exceptions import find_stack_level
2526

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

@@ -370,7 +371,7 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
370371
warnings.warn(
371372
"is_datetime64tz_dtype is deprecated and will be removed in a future "
372373
"version. Check `isinstance(dtype, pd.DatetimeTZDtype)` instead.",
373-
DeprecationWarning,
374+
Pandas4Warning,
374375
stacklevel=2,
375376
)
376377
if isinstance(arr_or_dtype, DatetimeTZDtype):
@@ -466,7 +467,7 @@ def is_period_dtype(arr_or_dtype) -> bool:
466467
warnings.warn(
467468
"is_period_dtype is deprecated and will be removed in a future version. "
468469
"Use `isinstance(dtype, pd.PeriodDtype)` instead",
469-
DeprecationWarning,
470+
Pandas4Warning,
470471
stacklevel=2,
471472
)
472473
if isinstance(arr_or_dtype, ExtensionDtype):
@@ -524,7 +525,7 @@ def is_interval_dtype(arr_or_dtype) -> bool:
524525
warnings.warn(
525526
"is_interval_dtype is deprecated and will be removed in a future version. "
526527
"Use `isinstance(dtype, pd.IntervalDtype)` instead",
527-
DeprecationWarning,
528+
Pandas4Warning,
528529
stacklevel=2,
529530
)
530531
if isinstance(arr_or_dtype, ExtensionDtype):
@@ -578,7 +579,7 @@ def is_categorical_dtype(arr_or_dtype) -> bool:
578579
warnings.warn(
579580
"is_categorical_dtype is deprecated and will be removed in a future "
580581
"version. Use isinstance(dtype, pd.CategoricalDtype) instead",
581-
DeprecationWarning,
582+
Pandas4Warning,
582583
stacklevel=2,
583584
)
584585
if isinstance(arr_or_dtype, ExtensionDtype):
@@ -973,7 +974,7 @@ def is_int64_dtype(arr_or_dtype) -> bool:
973974
warnings.warn(
974975
"is_int64_dtype is deprecated and will be removed in a future "
975976
"version. Use dtype == np.int64 instead.",
976-
DeprecationWarning,
977+
Pandas4Warning,
977978
stacklevel=2,
978979
)
979980
return _is_dtype_type(arr_or_dtype, classes(np.int64))
@@ -1436,7 +1437,7 @@ def is_bool_dtype(arr_or_dtype) -> bool:
14361437
"The behavior of is_bool_dtype with an object-dtype Index "
14371438
"of bool objects is deprecated. In a future version, "
14381439
"this will return False. Cast the Index to a bool dtype instead.",
1439-
DeprecationWarning,
1440+
Pandas4Warning,
14401441
stacklevel=2,
14411442
)
14421443
return True

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ def __init__(
727727
f"Passing a {type(data).__name__} to {type(self).__name__} "
728728
"is deprecated and will raise in a future version. "
729729
"Use public APIs instead.",
730-
DeprecationWarning,
730+
Pandas4Warning,
731731
stacklevel=2,
732732
)
733733

@@ -9894,7 +9894,7 @@ def stack(
98949894
"removed in a future version of pandas. See the What's New notes "
98959895
"for pandas 2.1.0 for details. Do not specify the future_stack "
98969896
"argument to adopt the new implementation and silence this warning.",
9897-
FutureWarning,
9897+
Pandas4Warning,
98989898
stacklevel=find_stack_level(),
98999899
)
99009900

pandas/core/generic.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9133,6 +9133,7 @@ def resample(
91339133
from pandas.core.resample import get_resampler
91349134

91359135
if convention is not lib.no_default:
9136+
# TODO: Enforce in 3.0 (#55968)
91369137
warnings.warn(
91379138
f"The 'convention' keyword in {type(self).__name__}.resample is "
91389139
"deprecated and will be removed in a future version. "

pandas/core/internals/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ def __getattr__(name: str):
2020
# GH#55139
2121
import warnings
2222

23+
from pandas.errors import Pandas4Warning
24+
2325
if name == "create_block_manager_from_blocks":
24-
# GH#33892
26+
# GH#33892, GH#58715
2527
warnings.warn(
2628
f"{name} is deprecated and will be removed in a future version. "
2729
"Use public APIs instead.",
28-
FutureWarning,
30+
Pandas4Warning,
2931
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
3032
# on hard-coding stacklevel
3133
stacklevel=2,
@@ -42,7 +44,7 @@ def __getattr__(name: str):
4244
warnings.warn(
4345
f"{name} is deprecated and will be removed in a future version. "
4446
"Use public APIs instead.",
45-
FutureWarning,
47+
Pandas4Warning,
4648
# https://github.com/pandas-dev/pandas/pull/55139#pullrequestreview-1720690758
4749
# on hard-coding stacklevel
4850
stacklevel=2,

0 commit comments

Comments
 (0)