diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index b15d0face7534..540fd638eb970 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -497,6 +497,8 @@ Deprecations ~~~~~~~~~~~~ - Deprecated argument ``infer_datetime_format`` in :func:`to_datetime` and :func:`read_csv`, as a strict version of it is now the default (:issue:`48621`) +- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) + .. --------------------------------------------------------------------------- .. _whatsnew_200.prior_deprecations: diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 352de34e71fc9..da4a36d63bcd2 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2199,7 +2199,7 @@ def is_boolean(self) -> bool: See Also -------- is_integer : Check if the Index only consists of integers. - is_floating : Check if the Index is a floating type. + 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_categorical : Check if the Index holds categorical data. @@ -2234,7 +2234,7 @@ def is_integer(self) -> bool: See Also -------- is_boolean : Check if the Index only consists of booleans. - is_floating : Check if the Index is a floating type. + 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_categorical : Check if the Index holds categorical data. @@ -2261,6 +2261,9 @@ def is_floating(self) -> bool: """ Check if the Index is a floating type. + .. deprecated:: 2.0.0 + Use `pandas.api.types.is_float_dtype` instead + The Index may consist of only floats, NaNs, or a mix of floats, integers, or NaNs. @@ -2297,6 +2300,12 @@ def is_floating(self) -> bool: >>> idx.is_floating() False """ + warnings.warn( + f"{type(self).__name__}.is_floating is deprecated." + "Use pandas.api.types.is_float_dtype instead", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.inferred_type in ["floating", "mixed-integer-float", "integer-na"] @final @@ -2313,7 +2322,7 @@ def is_numeric(self) -> bool: -------- is_boolean : Check if the Index only consists of booleans. is_integer : Check if the Index only consists of integers. - is_floating : Check if the Index is a floating type. + 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. is_interval : Check if the Index holds Interval objects. @@ -2356,7 +2365,7 @@ def is_object(self) -> bool: -------- is_boolean : Check if the Index only consists of booleans. is_integer : Check if the Index only consists of integers. - is_floating : Check if the Index is a floating type. + 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. is_interval : Check if the Index holds Interval objects. @@ -2397,7 +2406,7 @@ def is_categorical(self) -> bool: CategoricalIndex : Index for categorical data. is_boolean : Check if the Index only consists of booleans. is_integer : Check if the Index only consists of integers. - is_floating : Check if the Index is a floating type. + 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. @@ -2440,7 +2449,7 @@ def is_interval(self) -> bool: IntervalIndex : Index for Interval objects. is_boolean : Check if the Index only consists of booleans. is_integer : Check if the Index only consists of integers. - is_floating : Check if the Index is a floating type. + 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_categorical : Check if the Index holds categorical data. diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 2fb95942b08db..4d1e1f6f5de4f 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -795,6 +795,12 @@ def test_inv(self, simple_index): with pytest.raises(TypeError, match=msg): ~Series(idx) + def test_is_floating_is_deprecated(self, simple_index): + # GH50042 + idx = simple_index + with tm.assert_produces_warning(FutureWarning): + idx.is_floating() + class NumericBase(Base): """ diff --git a/pandas/tests/indexing/test_indexing.py b/pandas/tests/indexing/test_indexing.py index c7d8557e6e54c..12b435021480d 100644 --- a/pandas/tests/indexing/test_indexing.py +++ b/pandas/tests/indexing/test_indexing.py @@ -605,7 +605,7 @@ def test_index_type_coercion(self, indexer): s2 = s.copy() indexer(s2)[0.1] = 0 - assert s2.index.is_floating() + assert is_float_dtype(s2.index) assert indexer(s2)[0.1] == 0 s2 = s.copy() @@ -621,11 +621,11 @@ def test_index_type_coercion(self, indexer): for s in [Series(range(5), index=np.arange(5.0))]: - assert s.index.is_floating() + assert is_float_dtype(s.index) s2 = s.copy() indexer(s2)[0.1] = 0 - assert s2.index.is_floating() + assert is_float_dtype(s2.index) assert indexer(s2)[0.1] == 0 s2 = s.copy()