Skip to content

Commit 0e94a7a

Browse files
yuuunphofl
authored andcommitted
DEPR: deprecate Index.is_float (pandas-dev#50235)
1 parent 10644be commit 0e94a7a

File tree

4 files changed

+26
-9
lines changed

4 files changed

+26
-9
lines changed

doc/source/whatsnew/v2.0.0.rst

+2
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,8 @@ Deprecations
559559
- Deprecated :func:`pandas.io.sql.execute`(:issue:`50185`)
560560
-
561561

562+
- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`)
563+
562564
.. ---------------------------------------------------------------------------
563565
.. _whatsnew_200.prior_deprecations:
564566

pandas/core/indexes/base.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -2189,7 +2189,7 @@ def is_boolean(self) -> bool:
21892189
See Also
21902190
--------
21912191
is_integer : Check if the Index only consists of integers.
2192-
is_floating : Check if the Index is a floating type.
2192+
is_floating : Check if the Index is a floating type (deprecated).
21932193
is_numeric : Check if the Index only consists of numeric data.
21942194
is_object : Check if the Index is of the object dtype.
21952195
is_categorical : Check if the Index holds categorical data.
@@ -2224,7 +2224,7 @@ def is_integer(self) -> bool:
22242224
See Also
22252225
--------
22262226
is_boolean : Check if the Index only consists of booleans.
2227-
is_floating : Check if the Index is a floating type.
2227+
is_floating : Check if the Index is a floating type (deprecated).
22282228
is_numeric : Check if the Index only consists of numeric data.
22292229
is_object : Check if the Index is of the object dtype.
22302230
is_categorical : Check if the Index holds categorical data.
@@ -2251,6 +2251,9 @@ def is_floating(self) -> bool:
22512251
"""
22522252
Check if the Index is a floating type.
22532253
2254+
.. deprecated:: 2.0.0
2255+
Use `pandas.api.types.is_float_dtype` instead
2256+
22542257
The Index may consist of only floats, NaNs, or a mix of floats,
22552258
integers, or NaNs.
22562259
@@ -2287,6 +2290,12 @@ def is_floating(self) -> bool:
22872290
>>> idx.is_floating()
22882291
False
22892292
"""
2293+
warnings.warn(
2294+
f"{type(self).__name__}.is_floating is deprecated."
2295+
"Use pandas.api.types.is_float_dtype instead",
2296+
FutureWarning,
2297+
stacklevel=find_stack_level(),
2298+
)
22902299
return self.inferred_type in ["floating", "mixed-integer-float", "integer-na"]
22912300

22922301
@final
@@ -2303,7 +2312,7 @@ def is_numeric(self) -> bool:
23032312
--------
23042313
is_boolean : Check if the Index only consists of booleans.
23052314
is_integer : Check if the Index only consists of integers.
2306-
is_floating : Check if the Index is a floating type.
2315+
is_floating : Check if the Index is a floating type (deprecated).
23072316
is_object : Check if the Index is of the object dtype.
23082317
is_categorical : Check if the Index holds categorical data.
23092318
is_interval : Check if the Index holds Interval objects.
@@ -2346,7 +2355,7 @@ def is_object(self) -> bool:
23462355
--------
23472356
is_boolean : Check if the Index only consists of booleans.
23482357
is_integer : Check if the Index only consists of integers.
2349-
is_floating : Check if the Index is a floating type.
2358+
is_floating : Check if the Index is a floating type (deprecated).
23502359
is_numeric : Check if the Index only consists of numeric data.
23512360
is_categorical : Check if the Index holds categorical data.
23522361
is_interval : Check if the Index holds Interval objects.
@@ -2387,7 +2396,7 @@ def is_categorical(self) -> bool:
23872396
CategoricalIndex : Index for categorical data.
23882397
is_boolean : Check if the Index only consists of booleans.
23892398
is_integer : Check if the Index only consists of integers.
2390-
is_floating : Check if the Index is a floating type.
2399+
is_floating : Check if the Index is a floating type (deprecated).
23912400
is_numeric : Check if the Index only consists of numeric data.
23922401
is_object : Check if the Index is of the object dtype.
23932402
is_interval : Check if the Index holds Interval objects.
@@ -2430,7 +2439,7 @@ def is_interval(self) -> bool:
24302439
IntervalIndex : Index for Interval objects.
24312440
is_boolean : Check if the Index only consists of booleans.
24322441
is_integer : Check if the Index only consists of integers.
2433-
is_floating : Check if the Index is a floating type.
2442+
is_floating : Check if the Index is a floating type (deprecated).
24342443
is_numeric : Check if the Index only consists of numeric data.
24352444
is_object : Check if the Index is of the object dtype.
24362445
is_categorical : Check if the Index holds categorical data.

pandas/tests/indexes/common.py

+6
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,12 @@ def test_inv(self, simple_index):
795795
with pytest.raises(TypeError, match=msg):
796796
~Series(idx)
797797

798+
def test_is_floating_is_deprecated(self, simple_index):
799+
# GH50042
800+
idx = simple_index
801+
with tm.assert_produces_warning(FutureWarning):
802+
idx.is_floating()
803+
798804

799805
class NumericBase(Base):
800806
"""

pandas/tests/indexing/test_indexing.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ def test_index_type_coercion(self, indexer):
608608

609609
s2 = s.copy()
610610
indexer(s2)[0.1] = 0
611-
assert s2.index.is_floating()
611+
assert is_float_dtype(s2.index)
612612
assert indexer(s2)[0.1] == 0
613613

614614
s2 = s.copy()
@@ -624,11 +624,11 @@ def test_index_type_coercion(self, indexer):
624624

625625
for s in [Series(range(5), index=np.arange(5.0))]:
626626

627-
assert s.index.is_floating()
627+
assert is_float_dtype(s.index)
628628

629629
s2 = s.copy()
630630
indexer(s2)[0.1] = 0
631-
assert s2.index.is_floating()
631+
assert is_float_dtype(s2.index)
632632
assert indexer(s2)[0.1] == 0
633633

634634
s2 = s.copy()

0 commit comments

Comments
 (0)