Skip to content

Commit a7c7798

Browse files
committed
Update tests
1 parent e750d50 commit a7c7798

39 files changed

+147
-81
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5192,13 +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-
# TODO: Enforce in 3.0 (#59240)
5195+
from pandas.errors import Pandas4Warning
5196+
5197+
# https://github.com/pandas-dev/pandas/pull/59240
51965198
warnings.warn(
51975199
f"\'{name}\' is deprecated and will be removed "
51985200
f"in a future version, please use "
51995201
f"\'{c_PERIOD_AND_OFFSET_DEPR_FREQSTR.get(name)}\' "
52005202
f"instead.",
5201-
FutureWarning,
5203+
Pandas4Warning,
52025204
stacklevel=find_stack_level(),
52035205
)
52045206
return c_PERIOD_AND_OFFSET_DEPR_FREQSTR[name]
@@ -5207,13 +5209,15 @@ def _warn_about_deprecated_aliases(name: str, is_period: bool) -> str:
52075209
if name == _name:
52085210
continue
52095211
if _name in c_PERIOD_AND_OFFSET_DEPR_FREQSTR.values():
5210-
# TODO: Enforce in 3.0 (#59240)
5212+
from pandas.errors import Pandas4Warning
5213+
5214+
# https://github.com/pandas-dev/pandas/pull/59240
52115215
warnings.warn(
52125216
f"\'{name}\' is deprecated and will be removed "
52135217
f"in a future version, please use "
52145218
f"\'{_name}\' "
52155219
f"instead.",
5216-
FutureWarning,
5220+
Pandas4Warning,
52175221
stacklevel=find_stack_level(),
52185222
)
52195223
return _name

pandas/_libs/tslibs/timedeltas.pyx

Lines changed: 6 additions & 2 deletions
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,12 +724,14 @@ cpdef inline str parse_timedelta_unit(str unit):
722724
elif unit == "M":
723725
return unit
724726
elif unit in c_DEPR_UNITS:
725-
# TODO: Enforce in 3.0 (#59240)
727+
from pandas.errors import Pandas4Warning
728+
729+
# https://github.com/pandas-dev/pandas/pull/59240
726730
warnings.warn(
727731
f"\'{unit}\' is deprecated and will be removed in a "
728732
f"future version. Please use \'{c_DEPR_UNITS.get(unit)}\' "
729733
f"instead of \'{unit}\'.",
730-
FutureWarning,
734+
Pandas4Warning,
731735
stacklevel=find_stack_level(),
732736
)
733737
unit = c_DEPR_UNITS[unit]

pandas/core/arrays/string_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
pa_version_under12p1,
3030
)
3131
from pandas.compat.numpy import function as nv
32-
from pandas.errors import Pandas4Warning
3332
from pandas.util._decorators import (
3433
doc,
3534
set_module,
@@ -398,11 +397,12 @@ def _logical_method(self, other, op):
398397
):
399398
# GH#60234 backward compatibility for the move to StringDtype in 3.0
400399
op_name = op.__name__[1:].strip("_")
400+
# TODO: Enforce in 3.0 (#60234)
401401
warnings.warn(
402402
f"'{op_name}' operations between boolean dtype and {self.dtype} are "
403403
"deprecated and will raise in a future version. Explicitly "
404404
"cast the strings to a boolean dtype before operating instead.",
405-
Pandas4Warning,
405+
FutureWarning,
406406
stacklevel=find_stack_level(),
407407
)
408408
return op(other, self.astype(bool))

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/internals/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from pandas.errors import Pandas4Warning
2-
31
from pandas.core.internals.api import make_block # 2023-09-18 pyarrow uses this
42
from pandas.core.internals.concat import concatenate_managers
53
from pandas.core.internals.managers import (
@@ -22,6 +20,8 @@ def __getattr__(name: str):
2220
# GH#55139
2321
import warnings
2422

23+
from pandas.errors import Pandas4Warning
24+
2525
if name == "create_block_manager_from_blocks":
2626
# GH#33892, GH#58715
2727
warnings.warn(

pandas/core/internals/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def maybe_infer_ndim(values, placement: BlockPlacement, ndim: int | None) -> int
171171
"""
172172
warnings.warn(
173173
"maybe_infer_ndim is deprecated and will be removed in a future version.",
174-
DeprecationWarning,
174+
Pandas4Warning,
175175
stacklevel=2,
176176
)
177177
return _maybe_infer_ndim(values, placement, ndim)

pandas/core/internals/blocks.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from pandas.errors import (
4040
AbstractMethodError,
4141
OutOfBoundsDatetime,
42+
Pandas4Warning,
4243
)
4344
from pandas.util._decorators import cache_readonly
4445
from pandas.util._exceptions import find_stack_level
@@ -1899,7 +1900,7 @@ def fillna(
18991900
"need to implement this keyword or an exception will be "
19001901
"raised. In the interim, the keyword is ignored by "
19011902
f"{type(self.values).__name__}.",
1902-
DeprecationWarning,
1903+
Pandas4Warning,
19031904
stacklevel=find_stack_level(),
19041905
)
19051906

pandas/core/series.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,11 +4432,11 @@ def map(
44324432
if "arg" in kwargs:
44334433
# `.map(arg=my_func)`
44344434
func = kwargs.pop("arg")
4435-
# TODO: Enforce in 3.0 (#61264)
4435+
# https://github.com/pandas-dev/pandas/pull/61264
44364436
warnings.warn(
44374437
"The parameter `arg` has been renamed to `func`, and it "
44384438
"will stop being supported in a future version of pandas.",
4439-
FutureWarning,
4439+
Pandas4Warning,
44404440
stacklevel=find_stack_level(),
44414441
)
44424442
else:

pandas/tests/arrays/test_datetimes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import pytest
1212

1313
from pandas._libs.tslibs import tz_compare
14+
from pandas.errors import Pandas4Warning
1415

1516
from pandas.core.dtypes.dtypes import DatetimeTZDtype
1617

@@ -775,7 +776,7 @@ def test_date_range_uppercase_frequency_deprecated(self, freq_depr):
775776
)
776777

777778
expected = pd.date_range("1/1/2000", periods=4, freq=freq_depr.lower())
778-
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
779+
with tm.assert_produces_warning(Pandas4Warning, match=depr_msg):
779780
result = pd.date_range("1/1/2000", periods=4, freq=freq_depr)
780781
tm.assert_index_equal(result, expected)
781782

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

806807
expected = pd.date_range("1/1/2000", periods=4, freq="2W")
807-
with tm.assert_produces_warning(FutureWarning, match=depr_msg):
808+
with tm.assert_produces_warning(Pandas4Warning, match=depr_msg):
808809
result = pd.date_range("1/1/2000", periods=4, freq="2w")
809810
tm.assert_index_equal(result, expected)
810811

pandas/tests/dtypes/test_common.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55

66
from pandas.compat import HAS_PYARROW
7+
from pandas.errors import Pandas4Warning
78
import pandas.util._test_decorators as td
89

910
from pandas.core.dtypes.astype import astype_array
@@ -184,7 +185,7 @@ def test_get_dtype_error_catch(func):
184185
or func is com.is_categorical_dtype
185186
or func is com.is_period_dtype
186187
):
187-
warn = DeprecationWarning
188+
warn = Pandas4Warning
188189

189190
with tm.assert_produces_warning(warn, match=msg):
190191
assert not func(None)
@@ -204,7 +205,7 @@ def test_is_object():
204205
)
205206
def test_is_sparse(check_scipy):
206207
msg = "is_sparse is deprecated"
207-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
208+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
208209
assert com.is_sparse(SparseArray([1, 2, 3]))
209210

210211
assert not com.is_sparse(np.array([1, 2, 3]))
@@ -234,7 +235,7 @@ def test_is_datetime64_dtype():
234235

235236
def test_is_datetime64tz_dtype():
236237
msg = "is_datetime64tz_dtype is deprecated"
237-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
238+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
238239
assert not com.is_datetime64tz_dtype(object)
239240
assert not com.is_datetime64tz_dtype([1, 2, 3])
240241
assert not com.is_datetime64tz_dtype(pd.DatetimeIndex([1, 2, 3]))
@@ -250,7 +251,7 @@ def kind(self) -> str:
250251

251252
not_tz_dtype = NotTZDtype()
252253
msg = "is_datetime64tz_dtype is deprecated"
253-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
254+
with tm.assert_produces_warning(Pandas4Warning, match=msg):
254255
assert not com.is_datetime64tz_dtype(not_tz_dtype)
255256
assert not com.needs_i8_conversion(not_tz_dtype)
256257

0 commit comments

Comments
 (0)