Skip to content

Commit

Permalink
DEPR: deprecate Index.is_float (pandas-dev#50235)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuuun authored and phofl committed Jan 12, 2023
1 parent a60cb16 commit 84ab7c5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
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 @@ -559,6 +559,8 @@ Deprecations
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
-

- :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 @@ -2189,7 +2189,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 @@ -2224,7 +2224,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 @@ -2251,6 +2251,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 @@ -2287,6 +2290,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
Expand All @@ -2303,7 +2312,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 @@ -2346,7 +2355,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 @@ -2387,7 +2396,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 @@ -2430,7 +2439,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 @@ -608,7 +608,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 @@ -624,11 +624,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

0 comments on commit 84ab7c5

Please sign in to comment.