From 1c56bfb7b711d1aa28b5d3980efb6e097e890472 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 22:29:18 +0800 Subject: [PATCH 01/16] add new function --- pandas/core/arrays/categorical.py | 6 +++--- pandas/core/dtypes/api.py | 2 ++ pandas/core/dtypes/common.py | 14 +++++++------- pandas/core/indexes/base.py | 8 ++++---- pandas/plotting/_matplotlib/core.py | 4 ++-- pandas/tests/indexes/multi/test_equivalence.py | 4 ++-- pandas/tests/indexes/test_base.py | 4 ++-- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index f816b30b825b7..fb953e601735e 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -47,7 +47,7 @@ from pandas.core.dtypes.common import ( ensure_int64, ensure_platform_int, - is_any_numeric_dtype, + is_any_real_numeric_dtype, is_bool_dtype, is_categorical_dtype, is_datetime64_dtype, @@ -596,7 +596,7 @@ def _from_inferred_categories( if known_categories: # Convert to a specialized type with `dtype` if specified. - if is_any_numeric_dtype(dtype.categories): + if is_any_real_numeric_dtype(dtype.categories): cats = to_numeric(inferred_categories, errors="coerce") elif is_datetime64_dtype(dtype.categories): cats = to_datetime(inferred_categories, errors="coerce") @@ -1752,7 +1752,7 @@ def _values_for_rank(self): if mask.any(): values = values.astype("float64") values[mask] = np.nan - elif is_any_numeric_dtype(self.categories): + elif is_any_real_numeric_dtype(self.categories): values = np.array(self) else: # reorder the categories (so rank can use the float codes) diff --git a/pandas/core/dtypes/api.py b/pandas/core/dtypes/api.py index 00300c5c74e51..78201537ef021 100644 --- a/pandas/core/dtypes/api.py +++ b/pandas/core/dtypes/api.py @@ -26,6 +26,7 @@ is_named_tuple, is_number, is_numeric_dtype, + is_any_real_numeric_dtype, is_object_dtype, is_period_dtype, is_re, @@ -68,6 +69,7 @@ "is_named_tuple", "is_number", "is_numeric_dtype", + "is_any_real_numeric_dtype", "is_object_dtype", "is_period_dtype", "is_re", diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index fb9817de2b69b..463a6d533ee6c 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1219,7 +1219,7 @@ def is_numeric_dtype(arr_or_dtype) -> bool: ) -def is_any_numeric_dtype(arr_or_dtype) -> bool: +def is_any_real_numeric_dtype(arr_or_dtype) -> bool: """ Check whether the provided array or dtype is of a real number dtype @@ -1235,15 +1235,15 @@ def is_any_numeric_dtype(arr_or_dtype) -> bool: Examples ------- - >>> is_any_numeric_dtype(str) + >>> is_any_real_numeric_dtype(str) False - >>> is_any_numeric_dtype(int) + >>> is_any_real_numeric_dtype(int) True - >>> is_any_numeric_dtype(float) + >>> is_any_real_numeric_dtype(float) True - >>> is_any_numeric_dtype(complex(1,2)) + >>> is_any_real_numeric_dtype(complex(1,2)) False - >>> is_any_numeric_dtype(bool) + >>> is_any_real_numeric_dtype(bool) False """ return ( @@ -1808,7 +1808,7 @@ def is_all_strings(value: ArrayLike) -> bool: "is_nested_list_like", "is_number", "is_numeric_dtype", - "is_any_numeric_dtype", + "is_any_real_numeric_dtype", "is_numeric_v_string_like", "is_object_dtype", "is_period_dtype", diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 0caa8005f1ebc..ed2e3a7499728 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -88,7 +88,7 @@ ensure_int64, ensure_object, ensure_platform_int, - is_any_numeric_dtype, + is_any_real_numeric_dtype, is_bool_dtype, is_categorical_dtype, is_dtype_equal, @@ -2429,7 +2429,7 @@ def is_numeric(self) -> bool: """ warnings.warn( f"{type(self).__name__}.is_numeric is deprecated. " - "Use pandas.api.types.is_numeric_dtype instead", + "Use pandas.api.types.is_any_real_numeric_dtype instead", FutureWarning, stacklevel=find_stack_level(), ) @@ -6029,8 +6029,8 @@ def _should_compare(self, other: Index) -> bool: Check if `self == other` can ever have non-False entries. """ - if (is_bool_dtype(other) and is_any_numeric_dtype(self)) or ( - is_bool_dtype(self) and is_any_numeric_dtype(other) + if (is_bool_dtype(other) and is_any_real_numeric_dtype(self)) or ( + is_bool_dtype(self) and is_any_real_numeric_dtype(other) ): # GH#16877 Treat boolean labels passed to a numeric index as not # found. Without this fix False and True would be treated as 0 and 1 diff --git a/pandas/plotting/_matplotlib/core.py b/pandas/plotting/_matplotlib/core.py index 49b92e0984713..fd737cdcb967f 100644 --- a/pandas/plotting/_matplotlib/core.py +++ b/pandas/plotting/_matplotlib/core.py @@ -27,7 +27,7 @@ from pandas.util._exceptions import find_stack_level from pandas.core.dtypes.common import ( - is_any_numeric_dtype, + is_any_real_numeric_dtype, is_categorical_dtype, is_extension_array_dtype, is_float, @@ -841,7 +841,7 @@ def _get_xticks(self, convert_period: bool = False): if convert_period and isinstance(index, ABCPeriodIndex): self.data = self.data.reindex(index=index.sort_values()) x = self.data.index.to_timestamp()._mpl_repr() - elif is_any_numeric_dtype(index): + elif is_any_real_numeric_dtype(index): # Matplotlib supports numeric values or datetime objects as # xaxis values. Taking LBYL approach here, by the time # matplotlib raises exception when using non numeric/datetime diff --git a/pandas/tests/indexes/multi/test_equivalence.py b/pandas/tests/indexes/multi/test_equivalence.py index 3861d74cee092..9babbd5b8d56d 100644 --- a/pandas/tests/indexes/multi/test_equivalence.py +++ b/pandas/tests/indexes/multi/test_equivalence.py @@ -1,7 +1,7 @@ import numpy as np import pytest -from pandas.core.dtypes.common import is_any_numeric_dtype +from pandas.core.dtypes.common import is_any_real_numeric_dtype import pandas as pd from pandas import ( @@ -255,7 +255,7 @@ def test_is_all_dates(idx): def test_is_numeric(idx): # MultiIndex is never numeric - assert not is_any_numeric_dtype(idx) + assert not is_any_real_numeric_dtype(idx) def test_multiindex_compare(): diff --git a/pandas/tests/indexes/test_base.py b/pandas/tests/indexes/test_base.py index 27f501e1d7a19..783cf76403059 100644 --- a/pandas/tests/indexes/test_base.py +++ b/pandas/tests/indexes/test_base.py @@ -19,7 +19,7 @@ from pandas.util._test_decorators import async_mark from pandas.core.dtypes.common import ( - is_any_numeric_dtype, + is_any_real_numeric_dtype, is_numeric_dtype, is_object_dtype, ) @@ -659,7 +659,7 @@ def test_append_empty_preserve_name(self, name, expected): indirect=["index"], ) def test_is_numeric(self, index, expected): - assert is_any_numeric_dtype(index) is expected + assert is_any_real_numeric_dtype(index) is expected @pytest.mark.parametrize( "index, expected", From 8fc2bab22907ab30848710b35e8601edec959942 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 23:34:30 +0800 Subject: [PATCH 02/16] update doc --- doc/source/reference/arrays.rst | 1 + doc/source/whatsnew/v2.0.0.rst | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/source/reference/arrays.rst b/doc/source/reference/arrays.rst index aeaca7caea25d..bc3d465649433 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -666,6 +666,7 @@ Data type introspection api.types.is_integer_dtype api.types.is_interval_dtype api.types.is_numeric_dtype + api.types.is_any_real_numeric_dtype api.types.is_object_dtype api.types.is_period_dtype api.types.is_signed_integer_dtype diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 802e2e6a488d0..d4abd015b8918 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,6 +761,7 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) +- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to instead of :meth:`Index.is_numeric`(:issue:`51152`) .. --------------------------------------------------------------------------- .. _whatsnew_200.deprecations: @@ -775,7 +776,7 @@ Deprecations - :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`) - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) -- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_numeric_dtype` instead (:issue:`50042`) +- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_any_real_numeric_dtype` instead (:issue:`51152`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`) - :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) From a7dc1771dc1ed13e3ccbdadb95b76aeee6e71301 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 23:34:51 +0800 Subject: [PATCH 03/16] write test --- ci/code_checks.sh | 1 + pandas/tests/dtypes/test_common.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index cb66a1f350e8f..4c0d4c42af578 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -608,6 +608,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.api.types.is_list_like \ pandas.api.types.is_named_tuple \ pandas.api.types.is_numeric_dtype \ + pandas.api.types.is_any_real_numeric_dtype \ pandas.api.types.is_object_dtype \ pandas.api.types.is_period_dtype \ pandas.api.types.is_re \ diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index ce900ff649eec..d73007243e1d2 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -575,6 +575,20 @@ def _is_numeric(self) -> bool: assert com.is_numeric_dtype(MyNumericDType()) +def test_is_any_real_numeric_dtype(): + assert not com.is_any_real_numeric_dtype(str) + assert not com.is_any_real_numeric_dtype(bool) + assert not com.is_any_real_numeric_dtype(complex) + assert not com.is_any_real_numeric_dtype(object) + assert not com.is_any_real_numeric_dtype(np.datetime64) + assert not com.is_any_real_numeric_dtype(np.array(["a","b",complex(1,2)])) + assert not com.is_any_real_numeric_dtype(pd.DataFrame([complex(1,2),True])) + + assert com.is_any_real_numeric_dtype(int) + assert com.is_any_real_numeric_dtype(float) + assert com.is_any_real_numeric_dtype(pd.Series([1,2.5])) + + def test_is_float_dtype(): assert not com.is_float_dtype(str) assert not com.is_float_dtype(int) From 9e731bdbfa9ebe0a27f34a96dcdca59bf9922b49 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 23:42:45 +0800 Subject: [PATCH 04/16] write test --- pandas/core/dtypes/common.py | 10 ++++++++-- pandas/tests/dtypes/test_common.py | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 463a6d533ee6c..1b32e5f07af64 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1235,12 +1235,18 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool: Examples ------- - >>> is_any_real_numeric_dtype(str) - False >>> is_any_real_numeric_dtype(int) True >>> is_any_real_numeric_dtype(float) True + >>> is_any_real_numeric_dtype(np.array([1,2.5])) + True + >>> is_any_real_numeric_dtype(np.array(["a","b",complex(1,2)])) + False + >>> is_any_real_numeric_dtype(object) + False + >>> is_any_real_numeric_dtype(str) + False >>> is_any_real_numeric_dtype(complex(1,2)) False >>> is_any_real_numeric_dtype(bool) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index d73007243e1d2..3521e80dd42da 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -586,7 +586,7 @@ def test_is_any_real_numeric_dtype(): assert com.is_any_real_numeric_dtype(int) assert com.is_any_real_numeric_dtype(float) - assert com.is_any_real_numeric_dtype(pd.Series([1,2.5])) + assert com.is_any_real_numeric_dtype(np.array([1,2.5])) def test_is_float_dtype(): From 1dba6c65f80ce4aef85e3a7e89193c2669b974ae Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 23:52:24 +0800 Subject: [PATCH 05/16] pre-commit fix --- pandas/core/dtypes/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/api.py b/pandas/core/dtypes/api.py index 78201537ef021..cd424ea0d48f8 100644 --- a/pandas/core/dtypes/api.py +++ b/pandas/core/dtypes/api.py @@ -1,4 +1,5 @@ from pandas.core.dtypes.common import ( + is_any_real_numeric_dtype, is_array_like, is_bool, is_bool_dtype, @@ -26,7 +27,6 @@ is_named_tuple, is_number, is_numeric_dtype, - is_any_real_numeric_dtype, is_object_dtype, is_period_dtype, is_re, From ea39ebf072cd53a9eec6aa9fd9cb75bf5ead431e Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sat, 4 Feb 2023 23:57:08 +0800 Subject: [PATCH 06/16] pre-commit fix --- pandas/tests/dtypes/test_common.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/dtypes/test_common.py b/pandas/tests/dtypes/test_common.py index 3521e80dd42da..56062a55a4bde 100644 --- a/pandas/tests/dtypes/test_common.py +++ b/pandas/tests/dtypes/test_common.py @@ -581,12 +581,12 @@ def test_is_any_real_numeric_dtype(): assert not com.is_any_real_numeric_dtype(complex) assert not com.is_any_real_numeric_dtype(object) assert not com.is_any_real_numeric_dtype(np.datetime64) - assert not com.is_any_real_numeric_dtype(np.array(["a","b",complex(1,2)])) - assert not com.is_any_real_numeric_dtype(pd.DataFrame([complex(1,2),True])) + assert not com.is_any_real_numeric_dtype(np.array(["a", "b", complex(1, 2)])) + assert not com.is_any_real_numeric_dtype(pd.DataFrame([complex(1, 2), True])) assert com.is_any_real_numeric_dtype(int) assert com.is_any_real_numeric_dtype(float) - assert com.is_any_real_numeric_dtype(np.array([1,2.5])) + assert com.is_any_real_numeric_dtype(np.array([1, 2.5])) def test_is_float_dtype(): From df705574e94ed0571a1ba2377d3e252792c41277 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 00:49:40 +0800 Subject: [PATCH 07/16] fix error --- pandas/tests/api/test_types.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/api/test_types.py b/pandas/tests/api/test_types.py index 8c729fd19cbc7..0f89549f2ab03 100644 --- a/pandas/tests/api/test_types.py +++ b/pandas/tests/api/test_types.py @@ -8,6 +8,7 @@ class TestTypes(Base): allowed = [ + "is_any_real_numeric_dtype", "is_bool", "is_bool_dtype", "is_categorical_dtype", From f260a831d412bc164dfc61725a3000aa3155fdc9 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 01:51:34 +0800 Subject: [PATCH 08/16] fix --- pandas/core/dtypes/common.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 1b32e5f07af64..f86481cf23e22 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1221,7 +1221,7 @@ def is_numeric_dtype(arr_or_dtype) -> bool: def is_any_real_numeric_dtype(arr_or_dtype) -> bool: """ - Check whether the provided array or dtype is of a real number dtype + Check whether the provided array or dtype is of a real number dtype. Parameters ---------- @@ -1231,7 +1231,7 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool: Returns ------- boolean - Whether or not the array or dtype is of a real number dtype + Whether or not the array or dtype is of a real number dtype. Examples ------- From 6f3da1b240699f1fad458cc5edc489907d35f9c7 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 09:41:52 +0800 Subject: [PATCH 09/16] fix error --- doc/source/whatsnew/v2.0.0.rst | 4 ++-- pandas/core/dtypes/common.py | 8 +++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index d4abd015b8918..62fb5db836ce7 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,7 +761,7 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) -- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to instead of :meth:`Index.is_numeric`(:issue:`51152`) +- Added ``pandas.api.types.is_any_real_numeric_dtype`` to instead of :meth:`Index.is_numeric`(:issue:`51152`) .. --------------------------------------------------------------------------- .. _whatsnew_200.deprecations: @@ -776,7 +776,7 @@ Deprecations - :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`) - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) -- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_any_real_numeric_dtype` instead (:issue:`51152`) +- :meth:`Index.is_numeric` has been deprecated. Use ``pandas.api.types.is_any_real_numeric_dtype`` instead (:issue:`51152`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`) - :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index f86481cf23e22..54e6957e47b0a 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1221,7 +1221,7 @@ def is_numeric_dtype(arr_or_dtype) -> bool: def is_any_real_numeric_dtype(arr_or_dtype) -> bool: """ - Check whether the provided array or dtype is of a real number dtype. + Check whether the provided array or dtype is of real number dtype. Parameters ---------- @@ -1239,15 +1239,13 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool: True >>> is_any_real_numeric_dtype(float) True - >>> is_any_real_numeric_dtype(np.array([1,2.5])) + >>> is_any_real_numeric_dtype(np.array([1, 2.5])) True - >>> is_any_real_numeric_dtype(np.array(["a","b",complex(1,2)])) - False >>> is_any_real_numeric_dtype(object) False >>> is_any_real_numeric_dtype(str) False - >>> is_any_real_numeric_dtype(complex(1,2)) + >>> is_any_real_numeric_dtype(complex(1, 2)) False >>> is_any_real_numeric_dtype(bool) False From a329e4c70a6eb827eca2aa2c3e962e3bcdfe94c4 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 09:55:55 +0800 Subject: [PATCH 10/16] fix not found examples --- pandas/core/dtypes/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 54e6957e47b0a..c8bc15d683063 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1234,7 +1234,7 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool: Whether or not the array or dtype is of a real number dtype. Examples - ------- + -------- >>> is_any_real_numeric_dtype(int) True >>> is_any_real_numeric_dtype(float) From 02bf37246a09af6e6b7a74addde0ac20fd381b8f Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 09:58:13 +0800 Subject: [PATCH 11/16] fix not found examples --- pandas/core/dtypes/common.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index c8bc15d683063..e45ac38885cdd 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1221,7 +1221,7 @@ def is_numeric_dtype(arr_or_dtype) -> bool: def is_any_real_numeric_dtype(arr_or_dtype) -> bool: """ - Check whether the provided array or dtype is of real number dtype. + Check whether the provided array or dtype is of a real number dtype. Parameters ---------- From 44f91a18de0c4e1d6147be7b29ee9fdca87b6450 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 16:51:42 +0800 Subject: [PATCH 12/16] update whatsnew --- doc/source/whatsnew/v2.0.0.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 87a2edca501de..f3bd48719189a 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,7 +761,7 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) -- Added ``pandas.api.types.is_any_real_numeric_dtype`` to instead of :meth:`Index.is_numeric`(:issue:`51152`) +- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to instead of :meth:`Index.is_numeric`(:issue:`51152`) .. --------------------------------------------------------------------------- .. _whatsnew_200.deprecations: @@ -776,7 +776,7 @@ Deprecations - :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`) - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) -- :meth:`Index.is_numeric` has been deprecated. Use ``pandas.api.types.is_any_real_numeric_dtype`` instead (:issue:`51152`) +- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_any_real_numeric_dtype` instead (:issue:`51152`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`) - :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) From 2a3d209da5cf1c5250cbb0a2fa7199280363eb58 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Sun, 5 Feb 2023 20:08:13 +0800 Subject: [PATCH 13/16] update whatsnew --- pandas/core/dtypes/common.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index e45ac38885cdd..778a78f4fd2f9 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1239,8 +1239,6 @@ def is_any_real_numeric_dtype(arr_or_dtype) -> bool: True >>> is_any_real_numeric_dtype(float) True - >>> is_any_real_numeric_dtype(np.array([1, 2.5])) - True >>> is_any_real_numeric_dtype(object) False >>> is_any_real_numeric_dtype(str) From 7cda34554375c5c91bb2e0a7c65f2880c40cc00a Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Mon, 6 Feb 2023 09:41:49 +0800 Subject: [PATCH 14/16] update whatsnew and api.py --- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/core/dtypes/api.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index f3bd48719189a..5ab0db96da17c 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -761,7 +761,7 @@ Other API changes - The levels of the index of the :class:`Series` returned from ``Series.sparse.from_coo`` now always have dtype ``int32``. Previously they had dtype ``int64`` (:issue:`50926`) - :func:`to_datetime` with ``unit`` of either "Y" or "M" will now raise if a sequence contains a non-round ``float`` value, matching the ``Timestamp`` behavior (:issue:`50301`) - The methods :meth:`Series.round`, :meth:`DataFrame.__invert__`, :meth:`Series.__invert__`, :meth:`DataFrame.swapaxes`, :meth:`DataFrame.first`, :meth:`DataFrame.last`, :meth:`Series.first`, :meth:`Series.last` and :meth:`DataFrame.align` will now always return new objects (:issue:`51032`) -- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to instead of :meth:`Index.is_numeric`(:issue:`51152`) +- Added :func:`pandas.api.types.is_any_real_numeric_dtype` to check for real numeric dtypes (:issue:`51152`) .. --------------------------------------------------------------------------- .. _whatsnew_200.deprecations: diff --git a/pandas/core/dtypes/api.py b/pandas/core/dtypes/api.py index cd424ea0d48f8..254abe330b8e7 100644 --- a/pandas/core/dtypes/api.py +++ b/pandas/core/dtypes/api.py @@ -42,6 +42,7 @@ ) __all__ = [ + "is_any_real_numeric_dtype", "is_array_like", "is_bool", "is_bool_dtype", @@ -69,7 +70,6 @@ "is_named_tuple", "is_number", "is_numeric_dtype", - "is_any_real_numeric_dtype", "is_object_dtype", "is_period_dtype", "is_re", From c02aded31b6fe5c7e2ce07ced2c28d2dbae422e3 Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <1047068900@qq.com> Date: Tue, 7 Feb 2023 10:26:15 +0800 Subject: [PATCH 15/16] alphabetical update and keep old reference --- ci/code_checks.sh | 2 +- doc/source/reference/arrays.rst | 2 +- doc/source/whatsnew/v2.0.0.rst | 2 +- pandas/core/dtypes/common.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/code_checks.sh b/ci/code_checks.sh index 4c0d4c42af578..86c1eb169cd29 100755 --- a/ci/code_checks.sh +++ b/ci/code_checks.sh @@ -590,6 +590,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.Series.sparse.sp_values \ pandas.Timestamp.fromtimestamp \ pandas.api.types.infer_dtype \ + pandas.api.types.is_any_real_numeric_dtype \ pandas.api.types.is_bool_dtype \ pandas.api.types.is_categorical_dtype \ pandas.api.types.is_complex_dtype \ @@ -608,7 +609,6 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then pandas.api.types.is_list_like \ pandas.api.types.is_named_tuple \ pandas.api.types.is_numeric_dtype \ - pandas.api.types.is_any_real_numeric_dtype \ pandas.api.types.is_object_dtype \ pandas.api.types.is_period_dtype \ pandas.api.types.is_re \ diff --git a/doc/source/reference/arrays.rst b/doc/source/reference/arrays.rst index bc3d465649433..457edb46a7ec0 100644 --- a/doc/source/reference/arrays.rst +++ b/doc/source/reference/arrays.rst @@ -653,6 +653,7 @@ Data type introspection .. autosummary:: :toctree: api/ + api.types.is_any_real_numeric_dtype api.types.is_bool_dtype api.types.is_categorical_dtype api.types.is_complex_dtype @@ -666,7 +667,6 @@ Data type introspection api.types.is_integer_dtype api.types.is_interval_dtype api.types.is_numeric_dtype - api.types.is_any_real_numeric_dtype api.types.is_object_dtype api.types.is_period_dtype api.types.is_signed_integer_dtype diff --git a/doc/source/whatsnew/v2.0.0.rst b/doc/source/whatsnew/v2.0.0.rst index 5ab0db96da17c..99fbc0e6de518 100644 --- a/doc/source/whatsnew/v2.0.0.rst +++ b/doc/source/whatsnew/v2.0.0.rst @@ -776,7 +776,7 @@ Deprecations - :meth:`Index.is_integer` has been deprecated. Use :func:`pandas.api.types.is_integer_dtype` instead (:issue:`50042`) - :meth:`Index.is_floating` has been deprecated. Use :func:`pandas.api.types.is_float_dtype` instead (:issue:`50042`) - :meth:`Index.holds_integer` has been deprecated. Use :func:`pandas.api.types.infer_dtype` instead (:issue:`50243`) -- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_any_real_numeric_dtype` instead (:issue:`51152`) +- :meth:`Index.is_numeric` has been deprecated. Use :func:`pandas.api.types.is_any_real_numeric_dtype` instead (:issue:`50042`,:issue:`51152`) - :meth:`Index.is_categorical` has been deprecated. Use :func:`pandas.api.types.is_categorical_dtype` instead (:issue:`50042`) - :meth:`Index.is_object` has been deprecated. Use :func:`pandas.api.types.is_object_dtype` instead (:issue:`50042`) - :meth:`Index.is_interval` has been deprecated. Use :func:`pandas.api.types.is_intterval_dtype` instead (:issue:`50042`) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 778a78f4fd2f9..89126a67b762f 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1781,6 +1781,7 @@ def is_all_strings(value: ArrayLike) -> bool: "is_1d_only_ea_obj", "is_all_strings", "is_any_int_dtype", + "is_any_real_numeric_dtype", "is_array_like", "is_bool", "is_bool_dtype", @@ -1810,7 +1811,6 @@ def is_all_strings(value: ArrayLike) -> bool: "is_nested_list_like", "is_number", "is_numeric_dtype", - "is_any_real_numeric_dtype", "is_numeric_v_string_like", "is_object_dtype", "is_period_dtype", From 4cdc9ebfca2d2351d60c663eac545cddac6a141c Mon Sep 17 00:00:00 2001 From: ABCPAN-rank <76681118+ABCPAN-rank@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:44:03 +0800 Subject: [PATCH 16/16] conflict error When i solve conflict , I did wrong. --- pandas/core/dtypes/common.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 7ca9111cfca9f..eaa033e3d469a 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1752,7 +1752,6 @@ def is_all_strings(value: ArrayLike) -> bool: "is_nested_list_like", "is_number", "is_numeric_dtype", - "is_numeric_v_string_like", "is_object_dtype", "is_period_dtype", "is_re",