diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 3d12e334e7c0f..2245359fd8eac 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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)) @@ -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 diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 42043f95a7ace..c34c97b6e4f04 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -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 @@ -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) @@ -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])) @@ -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])) @@ -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) @@ -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")) @@ -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]) @@ -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]) @@ -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) @@ -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) diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index 4e8f375b31674..0dad0b05303ad 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -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"]) @@ -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) @@ -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")) @@ -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") @@ -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( @@ -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( @@ -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)) @@ -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))) @@ -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) diff --git a/pandas/tests/dtypes/test_inference.py b/pandas/tests/dtypes/test_inference.py index 32c8def669c21..ff2cfc1278331 100644 --- a/pandas/tests/dtypes/test_inference.py +++ b/pandas/tests/dtypes/test_inference.py @@ -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) @@ -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) diff --git a/pandas/tests/io/test_parquet.py b/pandas/tests/io/test_parquet.py index 9ae2d5cb03afd..ad7cdad363e78 100644 --- a/pandas/tests/io/test_parquet.py +++ b/pandas/tests/io/test_parquet.py @@ -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) diff --git a/pandas/tests/io/test_sql.py b/pandas/tests/io/test_sql.py index e20c49c072515..e3272e5f5902d 100644 --- a/pandas/tests/io/test_sql.py +++ b/pandas/tests/io/test_sql.py @@ -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 @@ -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: diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index 502096d41dde2..0e6f1c284a988 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -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 @@ -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"])