Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,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:
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 @@ -2200,7 +2200,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.
Expand Down Expand Up @@ -2235,7 +2235,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.
Expand All @@ -2262,6 +2262,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.

Expand Down Expand Up @@ -2298,6 +2301,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",
Comment on lines +2304 to +2305
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably could do with a space here.

FutureWarning,
stacklevel=find_stack_level(),
)
return self.inferred_type in ["floating", "mixed-integer-float", "integer-na"]

@final
Expand All @@ -2314,7 +2323,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.
Expand Down Expand Up @@ -2357,7 +2366,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.
Expand Down Expand Up @@ -2398,7 +2407,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.
Expand Down Expand Up @@ -2441,7 +2450,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.
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 @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/indexing/test_indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down