From 42632c10d8cc4d0095739edd26a355b187316b5a Mon Sep 17 00:00:00 2001 From: Akshay Jain Date: Tue, 18 Feb 2025 21:22:54 -0800 Subject: [PATCH 1/3] Improve examples for Series.str.isnumeric shared docstring to include fraction, decimals, negatives and exponents --- pandas/core/strings/accessor.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 75fbd642c3520..74401a25206ad 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -3549,12 +3549,29 @@ def casefold(self): also includes other characters that can represent quantities such as unicode fractions. - >>> s1 = pd.Series(['one', 'one1', '1', '']) + >>> s1 = pd.Series(['one', 'one1', '1', '', '³', '⅕']) >>> s1.str.isnumeric() 0 False 1 False 2 True 3 False + 4 True + 5 True + dtype: bool + + For a string to be considered numeric, all its characters must have a Unicode + numeric property. As a consequence, the following cases are **not** recognized + as numeric: + + - **Decimal numbers** (e.g., "1.1"): due to period ``"."`` + - **Negative numbers** (e.g., "-5"): due to minus sign ``"-"`` + - **Scientific notation** (e.g., "1e3"): due to characters like ``"e"`` + + >>> s2 = pd.Series(["1.1", "-5", "1e3"]) + >>> s2.str.isnumeric() + 0 False + 1 False + 2 False dtype: bool """ _shared_docs["isalnum"] = """ From c69d0269961e5f12dcf22da6d1823f0541a6d836 Mon Sep 17 00:00:00 2001 From: Akshay Jain Date: Tue, 18 Feb 2025 21:48:47 -0800 Subject: [PATCH 2/3] Fixed trailing white space issue using pre-commit hook --- pandas/core/strings/accessor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 74401a25206ad..1c9d42d185351 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -3559,13 +3559,13 @@ def casefold(self): 5 True dtype: bool - For a string to be considered numeric, all its characters must have a Unicode + For a string to be considered numeric, all its characters must have a Unicode numeric property. As a consequence, the following cases are **not** recognized as numeric: - - **Decimal numbers** (e.g., "1.1"): due to period ``"."`` - - **Negative numbers** (e.g., "-5"): due to minus sign ``"-"`` - - **Scientific notation** (e.g., "1e3"): due to characters like ``"e"`` + - **Decimal numbers** (e.g., "1.1"): due to period ``"."`` + - **Negative numbers** (e.g., "-5"): due to minus sign ``"-"`` + - **Scientific notation** (e.g., "1e3"): due to characters like ``"e"`` >>> s2 = pd.Series(["1.1", "-5", "1e3"]) >>> s2.str.isnumeric() From b265ad51c6456f94091593f384f5148c968597c1 Mon Sep 17 00:00:00 2001 From: Akshay Jain Date: Thu, 20 Feb 2025 15:43:58 -0800 Subject: [PATCH 3/3] DOC: Explicity mentioned type of Unicode numeric property in shared docstring for Series.str.isnumeric --- pandas/core/strings/accessor.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 1c9d42d185351..81f7441846589 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -3560,8 +3560,8 @@ def casefold(self): dtype: bool For a string to be considered numeric, all its characters must have a Unicode - numeric property. As a consequence, the following cases are **not** recognized - as numeric: + numeric property matching :py:meth:`str.is_numeric`. As a consequence, + the following cases are **not** recognized as numeric: - **Decimal numbers** (e.g., "1.1"): due to period ``"."`` - **Negative numbers** (e.g., "-5"): due to minus sign ``"-"``