Skip to content

Commit d36fb98

Browse files
Use DeprecationWarning instead of FutureWarning for is_.._dtype deprecations (#55703)
1 parent 5e4f2b2 commit d36fb98

File tree

7 files changed

+47
-49
lines changed

7 files changed

+47
-49
lines changed

pandas/core/dtypes/common.py

+14-14
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
@@ -499,8 +499,8 @@ def is_categorical_dtype(arr_or_dtype) -> bool:
499499
warnings.warn(
500500
"is_categorical_dtype is deprecated and will be removed in a future "
501501
"version. Use isinstance(dtype, pd.CategoricalDtype) instead",
502-
FutureWarning,
503-
stacklevel=find_stack_level(),
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

@@ -442,7 +444,7 @@ def test_is_not_unsigned_integer_dtype(dtype):
442444
)
443445
def test_is_int64_dtype(dtype):
444446
msg = "is_int64_dtype is deprecated"
445-
with tm.assert_produces_warning(FutureWarning, match=msg):
447+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
446448
assert com.is_int64_dtype(dtype)
447449

448450

@@ -480,7 +482,7 @@ def test_type_comparison_with_signed_int_ea_dtype_and_signed_int_numpy_dtype(
480482
)
481483
def test_is_not_int64_dtype(dtype):
482484
msg = "is_int64_dtype is deprecated"
483-
with tm.assert_produces_warning(FutureWarning, match=msg):
485+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
484486
assert not com.is_int64_dtype(dtype)
485487

486488

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"])
@@ -292,7 +292,7 @@ def test_subclass(self):
292292

293293
def test_compat(self, dtype):
294294
msg = "is_datetime64tz_dtype is deprecated"
295-
with tm.assert_produces_warning(FutureWarning, match=msg):
295+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
296296
assert is_datetime64tz_dtype(dtype)
297297
assert is_datetime64tz_dtype("datetime64[ns, US/Eastern]")
298298
assert is_datetime64_any_dtype(dtype)
@@ -353,14 +353,14 @@ def test_equality(self, dtype):
353353

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

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

362362
# dtypes
363-
with tm.assert_produces_warning(FutureWarning, match=msg):
363+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
364364
assert is_datetime64tz_dtype(s.dtype)
365365
assert is_datetime64tz_dtype(s)
366366
assert not is_datetime64tz_dtype(np.dtype("float64"))
@@ -531,7 +531,7 @@ def test_equality(self, dtype):
531531

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

537537
pidx = pd.period_range("2013-01-01 09:00", periods=5, freq="h")
@@ -619,7 +619,7 @@ def test_construction(self, subtype):
619619
i = IntervalDtype(subtype, closed="right")
620620
assert i.subtype == np.dtype("int64")
621621
msg = "is_interval_dtype is deprecated"
622-
with tm.assert_produces_warning(FutureWarning, match=msg):
622+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
623623
assert is_interval_dtype(i)
624624

625625
@pytest.mark.parametrize(
@@ -642,7 +642,7 @@ def test_construction_generic(self, subtype):
642642
i = IntervalDtype(subtype)
643643
assert i.subtype is None
644644
msg = "is_interval_dtype is deprecated"
645-
with tm.assert_produces_warning(FutureWarning, match=msg):
645+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
646646
assert is_interval_dtype(i)
647647

648648
@pytest.mark.parametrize(
@@ -815,7 +815,7 @@ def test_name_repr_generic(self, subtype):
815815

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

821821
ii = IntervalIndex.from_breaks(range(3))
@@ -830,7 +830,7 @@ def test_basic(self, dtype):
830830

831831
def test_basic_dtype(self):
832832
msg = "is_interval_dtype is deprecated"
833-
with tm.assert_produces_warning(FutureWarning, match=msg):
833+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
834834
assert is_interval_dtype("interval[int64, both]")
835835
assert is_interval_dtype(IntervalIndex.from_tuples([(0, 1)]))
836836
assert is_interval_dtype(IntervalIndex.from_breaks(np.arange(4)))
@@ -1178,7 +1178,7 @@ def test_is_dtype_no_warning(check):
11781178
or check is is_datetime64tz_dtype
11791179
or check is is_period_dtype
11801180
):
1181-
warn = FutureWarning
1181+
warn = DeprecationWarning
11821182

11831183
with tm.assert_produces_warning(warn, match=msg):
11841184
check(data)

pandas/tests/dtypes/test_inference.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ def test_is_datetime_dtypes(self):
18331833
assert is_datetime64_any_dtype(ts)
18341834
assert is_datetime64_any_dtype(tsa)
18351835

1836-
with tm.assert_produces_warning(FutureWarning, match=msg):
1836+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
18371837
assert not is_datetime64tz_dtype("datetime64")
18381838
assert not is_datetime64tz_dtype("datetime64[ns]")
18391839
assert not is_datetime64tz_dtype(ts)
@@ -1845,7 +1845,7 @@ def test_is_datetime_dtypes_with_tz(self, tz):
18451845
assert not is_datetime64_dtype(dtype)
18461846

18471847
msg = "is_datetime64tz_dtype is deprecated"
1848-
with tm.assert_produces_warning(FutureWarning, match=msg):
1848+
with tm.assert_produces_warning(DeprecationWarning, match=msg):
18491849
assert is_datetime64tz_dtype(dtype)
18501850
assert is_datetime64_ns_dtype(dtype)
18511851
assert is_datetime64_any_dtype(dtype)

pandas/tests/io/test_parquet.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,10 @@ def test_parquet_pos_args_deprecation(engine):
364364
)
365365
with tm.ensure_clean() as path:
366366
with tm.assert_produces_warning(
367-
FutureWarning, match=msg, check_stacklevel=False
367+
FutureWarning,
368+
match=msg,
369+
check_stacklevel=False,
370+
raise_on_extra_warnings=False,
368371
):
369372
df.to_parquet(path, engine)
370373

pandas/tests/io/test_sql.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ def test_dataframe_to_sql_arrow_dtypes(conn, request):
10181018
if conn == "sqlite_adbc_conn":
10191019
df = df.drop(columns=["timedelta"])
10201020
if pa_version_under14p1:
1021-
exp_warning = FutureWarning
1021+
exp_warning = DeprecationWarning
10221022
msg = "is_sparse is deprecated"
10231023
else:
10241024
exp_warning = None
@@ -1885,7 +1885,7 @@ def test_api_timedelta(conn, request):
18851885

18861886
if "adbc" in conn_name:
18871887
if pa_version_under14p1:
1888-
exp_warning = FutureWarning
1888+
exp_warning = DeprecationWarning
18891889
else:
18901890
exp_warning = None
18911891
else:

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
@@ -396,18 +395,12 @@ def test_constructor_categorical(self):
396395

397396
def test_construct_from_categorical_with_dtype(self):
398397
# GH12574
399-
cat = Series(Categorical([1, 2, 3]), dtype="category")
400-
msg = "is_categorical_dtype is deprecated"
401-
with tm.assert_produces_warning(FutureWarning, match=msg):
402-
assert is_categorical_dtype(cat)
403-
assert is_categorical_dtype(cat.dtype)
398+
ser = Series(Categorical([1, 2, 3]), dtype="category")
399+
assert isinstance(ser.dtype, CategoricalDtype)
404400

405401
def test_construct_intlist_values_category_dtype(self):
406402
ser = Series([1, 2, 3], dtype="category")
407-
msg = "is_categorical_dtype is deprecated"
408-
with tm.assert_produces_warning(FutureWarning, match=msg):
409-
assert is_categorical_dtype(ser)
410-
assert is_categorical_dtype(ser.dtype)
403+
assert isinstance(ser.dtype, CategoricalDtype)
411404

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

0 commit comments

Comments
 (0)