diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 605f1d4b26e13..c42f02c0be780 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -616,6 +616,7 @@ Deprecations - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) +- :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fc2c51166a737..62af72685a3e9 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2209,7 +2209,7 @@ def is_boolean(self) -> bool: is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. is_categorical : Check if the Index holds categorical data. - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2253,7 +2253,7 @@ def is_integer(self) -> bool: is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. is_categorical : Check if the Index holds categorical data (deprecated). - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2301,7 +2301,7 @@ def is_floating(self) -> bool: is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. is_categorical : Check if the Index holds categorical data (deprecated). - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2346,7 +2346,7 @@ def is_numeric(self) -> bool: is_floating : Check if the Index is a floating type (deprecated). is_object : Check if the Index is of the object dtype. is_categorical : Check if the Index holds categorical data (deprecated). - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2389,7 +2389,7 @@ def is_object(self) -> bool: is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. is_categorical : Check if the Index holds categorical data (deprecated). - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2433,7 +2433,7 @@ def is_categorical(self) -> bool: is_floating : Check if the Index is a floating type (deprecated). is_numeric : Check if the Index only consists of numeric data. is_object : Check if the Index is of the object dtype. - is_interval : Check if the Index holds Interval objects. + is_interval : Check if the Index holds Interval objects (deprecated). Examples -------- @@ -2470,6 +2470,9 @@ def is_interval(self) -> bool: """ Check if the Index holds Interval objects. + .. deprecated:: 2.0.0 + Use `pandas.api.types.is_interval_dtype` instead. + Returns ------- bool @@ -2496,6 +2499,12 @@ def is_interval(self) -> bool: >>> idx.is_interval() False """ + warnings.warn( + f"{type(self).__name__}.is_interval is deprecated." + "Use pandas.api.types.is_interval_dtype instead", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.inferred_type in ["interval"] @final diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index cb17e7529ec7b..cd4cf9dd61b97 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -823,6 +823,12 @@ def test_is_categorical_is_deprecated(self, simple_index): ): idx.is_categorical() + def test_is_interval_is_deprecated(self, simple_index): + # GH50042 + idx = simple_index + with tm.assert_produces_warning(FutureWarning): + idx.is_interval() + class NumericBase(Base): """