Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use DeprecationWarning instead of FutureWarning for is_.._dtype deprecations #55703

Merged
merged 5 commits into from
Dec 7, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ 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.",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)

dtype = getattr(arr, "dtype", arr)
Expand Down Expand Up @@ -329,8 +329,8 @@ 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.",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
if isinstance(arr_or_dtype, DatetimeTZDtype):
# GH#33400 fastpath for dtype object
Expand Down Expand Up @@ -408,8 +408,8 @@ 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",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
# GH#33400 fastpath for dtype object
Expand Down Expand Up @@ -454,8 +454,8 @@ 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",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
# GH#33400 fastpath for dtype object
Expand Down Expand Up @@ -499,8 +499,8 @@ 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",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
if isinstance(arr_or_dtype, ExtensionDtype):
# GH#33400 fastpath for dtype object
Expand Down Expand Up @@ -838,8 +838,8 @@ 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.",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
return _is_dtype_type(arr_or_dtype, classes(np.int64))

Expand Down Expand Up @@ -1241,8 +1241,8 @@ 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.",
FutureWarning,
stacklevel=find_stack_level(),
DeprecationWarning,
stacklevel=2,
)
return True
return False
Expand Down
22 changes: 12 additions & 10 deletions pandas/tests/dtypes/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ def get_is_dtype_funcs():
return [getattr(com, fname) for fname in fnames]


@pytest.mark.filterwarnings("ignore:is_categorical_dtype is deprecated:FutureWarning")
@pytest.mark.filterwarnings(
"ignore:is_categorical_dtype is deprecated:DeprecationWarning"
)
@pytest.mark.parametrize("func", get_is_dtype_funcs(), ids=lambda x: x.__name__)
def test_get_dtype_error_catch(func):
# see gh-15941
Expand All @@ -180,7 +182,7 @@ def test_get_dtype_error_catch(func):
or func is com.is_categorical_dtype
or func is com.is_period_dtype
):
warn = FutureWarning
warn = DeprecationWarning

with tm.assert_produces_warning(warn, match=msg):
assert not func(None)
Expand All @@ -200,7 +202,7 @@ def test_is_object():
)
def test_is_sparse(check_scipy):
msg = "is_sparse is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert com.is_sparse(SparseArray([1, 2, 3]))

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

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

not_tz_dtype = NotTZDtype()
msg = "is_datetime64tz_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert not com.is_datetime64tz_dtype(not_tz_dtype)
assert not com.needs_i8_conversion(not_tz_dtype)

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

def test_is_period_dtype():
msg = "is_period_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert not com.is_period_dtype(object)
assert not com.is_period_dtype([1, 2, 3])
assert not com.is_period_dtype(pd.Period("2017-01-01"))
Expand All @@ -279,7 +281,7 @@ def test_is_period_dtype():

def test_is_interval_dtype():
msg = "is_interval_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert not com.is_interval_dtype(object)
assert not com.is_interval_dtype([1, 2, 3])

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

def test_is_categorical_dtype():
msg = "is_categorical_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert not com.is_categorical_dtype(object)
assert not com.is_categorical_dtype([1, 2, 3])

Expand Down Expand Up @@ -442,7 +444,7 @@ def test_is_not_unsigned_integer_dtype(dtype):
)
def test_is_int64_dtype(dtype):
msg = "is_int64_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert com.is_int64_dtype(dtype)


Expand Down Expand Up @@ -480,7 +482,7 @@ def test_type_comparison_with_signed_int_ea_dtype_and_signed_int_numpy_dtype(
)
def test_is_not_int64_dtype(dtype):
msg = "is_int64_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert not com.is_int64_dtype(dtype)


Expand Down
20 changes: 10 additions & 10 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_is_dtype(self, dtype):

def test_basic(self, dtype):
msg = "is_categorical_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_categorical_dtype(dtype)

factor = Categorical(["a", "b", "b", "a", "a", "c", "c", "c"])
Expand Down Expand Up @@ -292,7 +292,7 @@ def test_subclass(self):

def test_compat(self, dtype):
msg = "is_datetime64tz_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_datetime64tz_dtype(dtype)
assert is_datetime64tz_dtype("datetime64[ns, US/Eastern]")
assert is_datetime64_any_dtype(dtype)
Expand Down Expand Up @@ -353,14 +353,14 @@ def test_equality(self, dtype):

def test_basic(self, dtype):
msg = "is_datetime64tz_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_datetime64tz_dtype(dtype)

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

# dtypes
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_datetime64tz_dtype(s.dtype)
assert is_datetime64tz_dtype(s)
assert not is_datetime64tz_dtype(np.dtype("float64"))
Expand Down Expand Up @@ -531,7 +531,7 @@ def test_equality(self, dtype):

def test_basic(self, dtype):
msg = "is_period_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_period_dtype(dtype)

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

@pytest.mark.parametrize(
Expand All @@ -642,7 +642,7 @@ def test_construction_generic(self, subtype):
i = IntervalDtype(subtype)
assert i.subtype is None
msg = "is_interval_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_interval_dtype(i)

@pytest.mark.parametrize(
Expand Down Expand Up @@ -815,7 +815,7 @@ def test_name_repr_generic(self, subtype):

def test_basic(self, dtype):
msg = "is_interval_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_interval_dtype(dtype)

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

def test_basic_dtype(self):
msg = "is_interval_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_interval_dtype("interval[int64, both]")
assert is_interval_dtype(IntervalIndex.from_tuples([(0, 1)]))
assert is_interval_dtype(IntervalIndex.from_breaks(np.arange(4)))
Expand Down Expand Up @@ -1178,7 +1178,7 @@ def test_is_dtype_no_warning(check):
or check is is_datetime64tz_dtype
or check is is_period_dtype
):
warn = FutureWarning
warn = DeprecationWarning

with tm.assert_produces_warning(warn, match=msg):
check(data)
Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -1833,7 +1833,7 @@ def test_is_datetime_dtypes(self):
assert is_datetime64_any_dtype(ts)
assert is_datetime64_any_dtype(tsa)

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

msg = "is_datetime64tz_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
with tm.assert_produces_warning(DeprecationWarning, match=msg):
assert is_datetime64tz_dtype(dtype)
assert is_datetime64_ns_dtype(dtype)
assert is_datetime64_any_dtype(dtype)
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/io/test_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,10 @@ def test_parquet_pos_args_deprecation(engine):
)
with tm.ensure_clean() as path:
with tm.assert_produces_warning(
FutureWarning, match=msg, check_stacklevel=False
FutureWarning,
match=msg,
check_stacklevel=False,
raise_on_extra_warnings=False,
):
df.to_parquet(path, engine)

Expand Down
4 changes: 2 additions & 2 deletions pandas/tests/io/test_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def test_dataframe_to_sql_arrow_dtypes(conn, request):
if conn == "sqlite_adbc_conn":
df = df.drop(columns=["timedelta"])
if pa_version_under14p1:
exp_warning = FutureWarning
exp_warning = DeprecationWarning
msg = "is_sparse is deprecated"
else:
exp_warning = None
Expand Down Expand Up @@ -1885,7 +1885,7 @@ def test_api_timedelta(conn, request):

if "adbc" in conn_name:
if pa_version_under14p1:
exp_warning = FutureWarning
exp_warning = DeprecationWarning
else:
exp_warning = None
else:
Expand Down
13 changes: 3 additions & 10 deletions pandas/tests/series/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from pandas.errors import IntCastingNaNError
import pandas.util._test_decorators as td

from pandas.core.dtypes.common import is_categorical_dtype
from pandas.core.dtypes.dtypes import CategoricalDtype

import pandas as pd
Expand Down Expand Up @@ -396,18 +395,12 @@ def test_constructor_categorical(self):

def test_construct_from_categorical_with_dtype(self):
# GH12574
cat = Series(Categorical([1, 2, 3]), dtype="category")
msg = "is_categorical_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
assert is_categorical_dtype(cat)
assert is_categorical_dtype(cat.dtype)
ser = Series(Categorical([1, 2, 3]), dtype="category")
assert isinstance(ser.dtype, CategoricalDtype)

def test_construct_intlist_values_category_dtype(self):
ser = Series([1, 2, 3], dtype="category")
msg = "is_categorical_dtype is deprecated"
with tm.assert_produces_warning(FutureWarning, match=msg):
assert is_categorical_dtype(ser)
assert is_categorical_dtype(ser.dtype)
assert isinstance(ser.dtype, CategoricalDtype)

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