From d37573fb679658b1c1ad50f7724849e21f07e79a Mon Sep 17 00:00:00 2001 From: yuuun Date: Wed, 14 Dec 2022 00:15:28 +0900 Subject: [PATCH 1/6] deprecate is_float() --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/core/indexes/base.py | 21 +++++++++++++++------ pandas/tests/indexes/common.py | 6 ++++++ pandas/tests/indexing/test_indexing.py | 6 +++--- 4 files changed, 25 insertions(+), 10 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index e16ef0857685d..fd6950f52bd46 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -416,7 +416,7 @@ Other API changes Deprecations ~~~~~~~~~~~~ -- +- :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) .. --------------------------------------------------------------------------- diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0959f44e62576..4c9cf1638fecd 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2201,7 +2201,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. @@ -2236,7 +2236,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. @@ -2266,6 +2266,9 @@ def is_floating(self) -> bool: The Index may consist of only floats, NaNs, or a mix of floats, integers, or NaNs. + ..deprecated:: 2.0.0 + Use `pandas.api.types.is_float_dtype` instead + Returns ------- bool @@ -2299,6 +2302,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_type instead", + FutureWarning, + stacklevel=find_stack_level(), + ) return self.inferred_type in ["floating", "mixed-integer-float", "integer-na"] @final @@ -2315,7 +2324,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. @@ -2358,7 +2367,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. @@ -2399,7 +2408,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. @@ -2442,7 +2451,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..3800e10fb285c 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() From 6a080b3ee793a41d6c671736463a51d1c12459bc Mon Sep 17 00:00:00 2001 From: yun Date: Wed, 14 Dec 2022 01:50:28 +0900 Subject: [PATCH 2/6] update is_floating() --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 5a54860dbeea5..39c7dccc960c0 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2304,7 +2304,7 @@ def is_floating(self) -> bool: """ warnings.warn( f"{type(self).__name__}.is_floating is deprecated." - "Use pandas.api.types.is_float_type instead", + "Use pandas.api.types.is_float_dtype instead", FutureWarning, stacklevel=find_stack_level(), ) From 8b8674044dfccf7e4a34eb837bd7c2b748dd5832 Mon Sep 17 00:00:00 2001 From: yuuun Date: Wed, 14 Dec 2022 02:04:14 +0900 Subject: [PATCH 3/6] update error --- pandas/core/indexes/base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 39c7dccc960c0..fe6891d803d26 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2266,7 +2266,7 @@ def is_floating(self) -> bool: The Index may consist of only floats, NaNs, or a mix of floats, integers, or NaNs. - ..deprecated:: 2.0.0 + .. deprecated:: 2.0.0 Use `pandas.api.types.is_float_dtype` instead Returns From b18d8db1799038ff20680177e7e12d4f661c492a Mon Sep 17 00:00:00 2001 From: yun Date: Wed, 14 Dec 2022 10:55:23 +0900 Subject: [PATCH 4/6] reorder --- pandas/core/indexes/base.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index fe6891d803d26..b47a8f3e1cb35 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2263,12 +2263,12 @@ def is_floating(self) -> bool: """ Check if the Index is a floating type. - The Index may consist of only floats, NaNs, or a mix of floats, - integers, or NaNs. - .. 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. + Returns ------- bool From ce30d07aa9299d2ee21e132176b8b865af84bca4 Mon Sep 17 00:00:00 2001 From: yun Date: Wed, 14 Dec 2022 11:36:54 +0900 Subject: [PATCH 5/6] check indent error --- pandas/core/indexes/base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index b47a8f3e1cb35..2c52d482bb719 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -2303,11 +2303,11 @@ def is_floating(self) -> bool: False """ warnings.warn( - f"{type(self).__name__}.is_floating is deprecated." - "Use pandas.api.types.is_float_dtype instead", - FutureWarning, - stacklevel=find_stack_level(), - ) + 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 From aba7816d851ba10a2932d29f92ca5ae390061a03 Mon Sep 17 00:00:00 2001 From: yun Date: Wed, 14 Dec 2022 11:44:50 +0900 Subject: [PATCH 6/6] fixing indent error --- pandas/tests/indexes/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/tests/indexes/common.py b/pandas/tests/indexes/common.py index 3800e10fb285c..4d1e1f6f5de4f 100644 --- a/pandas/tests/indexes/common.py +++ b/pandas/tests/indexes/common.py @@ -796,10 +796,10 @@ def test_inv(self, simple_index): ~Series(idx) def test_is_floating_is_deprecated(self, simple_index): - # GH50042 - idx = simple_index - with tm.assert_produces_warning(FutureWarning): - idx.is_floating() + # GH50042 + idx = simple_index + with tm.assert_produces_warning(FutureWarning): + idx.is_floating() class NumericBase(Base):