Skip to content

Commit

Permalink
DEPR: deprecate Index.is_interval (#50196)
Browse files Browse the repository at this point in the history
* assertion error fix added in pandas/core/indexes/base.py

* changes made to pandas/core/infexes/base.py for is_interval deprecation in class Index

* changes made to pandas/tests//indexes/common.py to test deprecation of is_interval

* docs/source/whatsnew/v2.0.0.rst edited for index.is_interval

* changes in pandas/core/indexes/base.py - removed extra import of is_interva;_dtype

* brnahc state before rebase

* Fixed error in .pre-commit-config.yaml file

* unwanted changed fixed in .pre-commit-cofig.yaml
  • Loading branch information
ShisuiUzumaki committed Jan 24, 2023
1 parent 3886ff7 commit be260f1
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,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:
Expand Down
21 changes: 15 additions & 6 deletions pandas/core/indexes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2228,7 +2228,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
--------
Expand Down Expand Up @@ -2272,7 +2272,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
--------
Expand Down Expand Up @@ -2320,7 +2320,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
--------
Expand Down Expand Up @@ -2365,7 +2365,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
--------
Expand Down Expand Up @@ -2408,7 +2408,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
--------
Expand Down Expand Up @@ -2452,7 +2452,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
--------
Expand Down Expand Up @@ -2489,6 +2489,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
Expand All @@ -2515,6 +2518,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
Expand Down
6 changes: 6 additions & 0 deletions pandas/tests/indexes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down

0 comments on commit be260f1

Please sign in to comment.