Skip to content

Commit 7006d99

Browse files
Backport PR pandas-dev#55703 on branch 2.1.x (Use DeprecationWarning instead of FutureWarning for is_.._dtype deprecations) (pandas-dev#56377)
Use DeprecationWarning instead of FutureWarning for is_.._dtype deprecations (pandas-dev#55703) (cherry picked from commit d36fb98)
1 parent 65723ab commit 7006d99

File tree

5 files changed

+42
-47
lines changed

5 files changed

+42
-47
lines changed

pandas/core/dtypes/common.py

+15-15
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ def is_sparse(arr) -> bool:
211211
warnings.warn(
212212
"is_sparse is deprecated and will be removed in a future "
213213
"version. Check `isinstance(dtype, pd.SparseDtype)` instead.",
214-
FutureWarning,
215-
stacklevel=find_stack_level(),
214+
DeprecationWarning,
215+
stacklevel=2,
216216
)
217217

218218
dtype = getattr(arr, "dtype", arr)
@@ -329,8 +329,8 @@ def is_datetime64tz_dtype(arr_or_dtype) -> bool:
329329
warnings.warn(
330330
"is_datetime64tz_dtype is deprecated and will be removed in a future "
331331
"version. Check `isinstance(dtype, pd.DatetimeTZDtype)` instead.",
332-
FutureWarning,
333-
stacklevel=find_stack_level(),
332+
DeprecationWarning,
333+
stacklevel=2,
334334
)
335335
if isinstance(arr_or_dtype, DatetimeTZDtype):
336336
# GH#33400 fastpath for dtype object
@@ -408,8 +408,8 @@ def is_period_dtype(arr_or_dtype) -> bool:
408408
warnings.warn(
409409
"is_period_dtype is deprecated and will be removed in a future version. "
410410
"Use `isinstance(dtype, pd.PeriodDtype)` instead",
411-
FutureWarning,
412-
stacklevel=find_stack_level(),
411+
DeprecationWarning,
412+
stacklevel=2,
413413
)
414414
if isinstance(arr_or_dtype, ExtensionDtype):
415415
# GH#33400 fastpath for dtype object
@@ -454,8 +454,8 @@ def is_interval_dtype(arr_or_dtype) -> bool:
454454
warnings.warn(
455455
"is_interval_dtype is deprecated and will be removed in a future version. "
456456
"Use `isinstance(dtype, pd.IntervalDtype)` instead",
457-
FutureWarning,
458-
stacklevel=find_stack_level(),
457+
DeprecationWarning,
458+
stacklevel=2,
459459
)
460460
if isinstance(arr_or_dtype, ExtensionDtype):
461461
# GH#33400 fastpath for dtype object
@@ -498,9 +498,9 @@ def is_categorical_dtype(arr_or_dtype) -> bool:
498498
# GH#52527
499499
warnings.warn(
500500
"is_categorical_dtype is deprecated and will be removed in a future "
501-
"version. Use isinstance(dtype, CategoricalDtype) instead",
502-
FutureWarning,
503-
stacklevel=find_stack_level(),
501+
"version. Use isinstance(dtype, pd.CategoricalDtype) instead",
502+
DeprecationWarning,
503+
stacklevel=2,
504504
)
505505
if isinstance(arr_or_dtype, ExtensionDtype):
506506
# GH#33400 fastpath for dtype object
@@ -838,8 +838,8 @@ def is_int64_dtype(arr_or_dtype) -> bool:
838838
warnings.warn(
839839
"is_int64_dtype is deprecated and will be removed in a future "
840840
"version. Use dtype == np.int64 instead.",
841-
FutureWarning,
842-
stacklevel=find_stack_level(),
841+
DeprecationWarning,
842+
stacklevel=2,
843843
)
844844
return _is_dtype_type(arr_or_dtype, classes(np.int64))
845845

@@ -1241,8 +1241,8 @@ def is_bool_dtype(arr_or_dtype) -> bool:
12411241
"The behavior of is_bool_dtype with an object-dtype Index "
12421242
"of bool objects is deprecated. In a future version, "
12431243
"this will return False. Cast the Index to a bool dtype instead.",
1244-
FutureWarning,
1245-
stacklevel=find_stack_level(),
1244+
DeprecationWarning,
1245+
stacklevel=2,
12461246
)
12471247
return True
12481248
return False

pandas/tests/dtypes/test_common.py

+12-10
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def get_is_dtype_funcs():
164164
return [getattr(com, fname) for fname in fnames]
165165

166166

167-
@pytest.mark.filterwarnings("ignore:is_categorical_dtype is deprecated:FutureWarning")
167+
@pytest.mark.filterwarnings(
168+
"ignore:is_categorical_dtype is deprecated:DeprecationWarning"
169+
)
168170
@pytest.mark.parametrize("func", get_is_dtype_funcs(), ids=lambda x: x.__name__)
169171
def test_get_dtype_error_catch(func):
170172
# see gh-15941
@@ -180,7 +182,7 @@ def test_get_dtype_error_catch(func):
180182
or func is com.is_categorical_dtype
181183
or func is com.is_period_dtype
182184
):
183-
warn = FutureWarning
185+
warn = DeprecationWarning
184186

185187
with tm.assert_produces_warning(warn, match=msg):
186188
assert not func(None)
@@ -200,7 +202,7 @@ def test_is_object():
200202
)
201203
def test_is_sparse(check_scipy):
202204
msg = "is_sparse is deprecated"
203-
with tm.assert_produces_warning(FutureWarning, match=msg):
205+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
204206
assert com.is_sparse(SparseArray([1, 2, 3]))
205207

206208
assert not com.is_sparse(np.array([1, 2, 3]))
@@ -230,7 +232,7 @@ def test_is_datetime64_dtype():
230232

231233
def test_is_datetime64tz_dtype():
232234
msg = "is_datetime64tz_dtype is deprecated"
233-
with tm.assert_produces_warning(FutureWarning, match=msg):
235+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
234236
assert not com.is_datetime64tz_dtype(object)
235237
assert not com.is_datetime64tz_dtype([1, 2, 3])
236238
assert not com.is_datetime64tz_dtype(pd.DatetimeIndex([1, 2, 3]))
@@ -246,7 +248,7 @@ def kind(self) -> str:
246248

247249
not_tz_dtype = NotTZDtype()
248250
msg = "is_datetime64tz_dtype is deprecated"
249-
with tm.assert_produces_warning(FutureWarning, match=msg):
251+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
250252
assert not com.is_datetime64tz_dtype(not_tz_dtype)
251253
assert not com.needs_i8_conversion(not_tz_dtype)
252254

@@ -268,7 +270,7 @@ def test_is_timedelta64_dtype():
268270

269271
def test_is_period_dtype():
270272
msg = "is_period_dtype is deprecated"
271-
with tm.assert_produces_warning(FutureWarning, match=msg):
273+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
272274
assert not com.is_period_dtype(object)
273275
assert not com.is_period_dtype([1, 2, 3])
274276
assert not com.is_period_dtype(pd.Period("2017-01-01"))
@@ -279,7 +281,7 @@ def test_is_period_dtype():
279281

280282
def test_is_interval_dtype():
281283
msg = "is_interval_dtype is deprecated"
282-
with tm.assert_produces_warning(FutureWarning, match=msg):
284+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
283285
assert not com.is_interval_dtype(object)
284286
assert not com.is_interval_dtype([1, 2, 3])
285287

@@ -292,7 +294,7 @@ def test_is_interval_dtype():
292294

293295
def test_is_categorical_dtype():
294296
msg = "is_categorical_dtype is deprecated"
295-
with tm.assert_produces_warning(FutureWarning, match=msg):
297+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
296298
assert not com.is_categorical_dtype(object)
297299
assert not com.is_categorical_dtype([1, 2, 3])
298300

@@ -433,7 +435,7 @@ def test_is_not_unsigned_integer_dtype(dtype):
433435
)
434436
def test_is_int64_dtype(dtype):
435437
msg = "is_int64_dtype is deprecated"
436-
with tm.assert_produces_warning(FutureWarning, match=msg):
438+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
437439
assert com.is_int64_dtype(dtype)
438440

439441

@@ -471,7 +473,7 @@ def test_type_comparison_with_signed_int_ea_dtype_and_signed_int_numpy_dtype(
471473
)
472474
def test_is_not_int64_dtype(dtype):
473475
msg = "is_int64_dtype is deprecated"
474-
with tm.assert_produces_warning(FutureWarning, match=msg):
476+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
475477
assert not com.is_int64_dtype(dtype)
476478

477479

pandas/tests/dtypes/test_dtypes.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def test_is_dtype(self, dtype):
166166

167167
def test_basic(self, dtype):
168168
msg = "is_categorical_dtype is deprecated"
169-
with tm.assert_produces_warning(FutureWarning, match=msg):
169+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
170170
assert is_categorical_dtype(dtype)
171171

172172
factor = Categorical(["a", "b", "b", "a", "a", "c", "c", "c"])
@@ -291,7 +291,7 @@ def test_subclass(self):
291291

292292
def test_compat(self, dtype):
293293
msg = "is_datetime64tz_dtype is deprecated"
294-
with tm.assert_produces_warning(FutureWarning, match=msg):
294+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
295295
assert is_datetime64tz_dtype(dtype)
296296
assert is_datetime64tz_dtype("datetime64[ns, US/Eastern]")
297297
assert is_datetime64_any_dtype(dtype)
@@ -352,14 +352,14 @@ def test_equality(self, dtype):
352352

353353
def test_basic(self, dtype):
354354
msg = "is_datetime64tz_dtype is deprecated"
355-
with tm.assert_produces_warning(FutureWarning, match=msg):
355+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
356356
assert is_datetime64tz_dtype(dtype)
357357

358358
dr = date_range("20130101", periods=3, tz="US/Eastern")
359359
s = Series(dr, name="A")
360360

361361
# dtypes
362-
with tm.assert_produces_warning(FutureWarning, match=msg):
362+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
363363
assert is_datetime64tz_dtype(s.dtype)
364364
assert is_datetime64tz_dtype(s)
365365
assert not is_datetime64tz_dtype(np.dtype("float64"))
@@ -530,7 +530,7 @@ def test_equality(self, dtype):
530530

531531
def test_basic(self, dtype):
532532
msg = "is_period_dtype is deprecated"
533-
with tm.assert_produces_warning(FutureWarning, match=msg):
533+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
534534
assert is_period_dtype(dtype)
535535

536536
pidx = pd.period_range("2013-01-01 09:00", periods=5, freq="H")
@@ -618,7 +618,7 @@ def test_construction(self, subtype):
618618
i = IntervalDtype(subtype, closed="right")
619619
assert i.subtype == np.dtype("int64")
620620
msg = "is_interval_dtype is deprecated"
621-
with tm.assert_produces_warning(FutureWarning, match=msg):
621+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
622622
assert is_interval_dtype(i)
623623

624624
@pytest.mark.parametrize(
@@ -641,7 +641,7 @@ def test_construction_generic(self, subtype):
641641
i = IntervalDtype(subtype)
642642
assert i.subtype is None
643643
msg = "is_interval_dtype is deprecated"
644-
with tm.assert_produces_warning(FutureWarning, match=msg):
644+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
645645
assert is_interval_dtype(i)
646646

647647
@pytest.mark.parametrize(
@@ -814,7 +814,7 @@ def test_name_repr_generic(self, subtype):
814814

815815
def test_basic(self, dtype):
816816
msg = "is_interval_dtype is deprecated"
817-
with tm.assert_produces_warning(FutureWarning, match=msg):
817+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
818818
assert is_interval_dtype(dtype)
819819

820820
ii = IntervalIndex.from_breaks(range(3))
@@ -829,7 +829,7 @@ def test_basic(self, dtype):
829829

830830
def test_basic_dtype(self):
831831
msg = "is_interval_dtype is deprecated"
832-
with tm.assert_produces_warning(FutureWarning, match=msg):
832+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
833833
assert is_interval_dtype("interval[int64, both]")
834834
assert is_interval_dtype(IntervalIndex.from_tuples([(0, 1)]))
835835
assert is_interval_dtype(IntervalIndex.from_breaks(np.arange(4)))
@@ -1158,7 +1158,7 @@ def test_is_dtype_no_warning(check):
11581158
or check is is_datetime64tz_dtype
11591159
or check is is_period_dtype
11601160
):
1161-
warn = FutureWarning
1161+
warn = DeprecationWarning
11621162

11631163
with tm.assert_produces_warning(warn, match=msg):
11641164
check(data)

pandas/tests/dtypes/test_inference.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ def test_is_datetime_dtypes(self):
18211821
assert is_datetime64_any_dtype(ts)
18221822
assert is_datetime64_any_dtype(tsa)
18231823

1824-
with tm.assert_produces_warning(FutureWarning, match=msg):
1824+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
18251825
assert not is_datetime64tz_dtype("datetime64")
18261826
assert not is_datetime64tz_dtype("datetime64[ns]")
18271827
assert not is_datetime64tz_dtype(ts)
@@ -1833,7 +1833,7 @@ def test_is_datetime_dtypes_with_tz(self, tz):
18331833
assert not is_datetime64_dtype(dtype)
18341834

18351835
msg = "is_datetime64tz_dtype is deprecated"
1836-
with tm.assert_produces_warning(FutureWarning, match=msg):
1836+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
18371837
assert is_datetime64tz_dtype(dtype)
18381838
assert is_datetime64_ns_dtype(dtype)
18391839
assert is_datetime64_any_dtype(dtype)

pandas/tests/series/test_constructors.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
from pandas.errors import IntCastingNaNError
1818
import pandas.util._test_decorators as td
1919

20-
from pandas.core.dtypes.common import is_categorical_dtype
2120
from pandas.core.dtypes.dtypes import CategoricalDtype
2221

2322
import pandas as pd
@@ -393,18 +392,12 @@ def test_constructor_categorical(self):
393392

394393
def test_construct_from_categorical_with_dtype(self):
395394
# GH12574
396-
cat = Series(Categorical([1, 2, 3]), dtype="category")
397-
msg = "is_categorical_dtype is deprecated"
398-
with tm.assert_produces_warning(FutureWarning, match=msg):
399-
assert is_categorical_dtype(cat)
400-
assert is_categorical_dtype(cat.dtype)
395+
ser = Series(Categorical([1, 2, 3]), dtype="category")
396+
assert isinstance(ser.dtype, CategoricalDtype)
401397

402398
def test_construct_intlist_values_category_dtype(self):
403399
ser = Series([1, 2, 3], dtype="category")
404-
msg = "is_categorical_dtype is deprecated"
405-
with tm.assert_produces_warning(FutureWarning, match=msg):
406-
assert is_categorical_dtype(ser)
407-
assert is_categorical_dtype(ser.dtype)
400+
assert isinstance(ser.dtype, CategoricalDtype)
408401

409402
def test_constructor_categorical_with_coercion(self):
410403
factor = Categorical(["a", "b", "b", "a", "a", "c", "c", "c"])

0 commit comments

Comments
 (0)