Skip to content

BUG: fix .str.isdigit to honor unicode superscript for older pyarrow #61962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/source/whatsnew/v2.3.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ become the default string dtype in pandas 3.0. See

Bug fixes
^^^^^^^^^
-
- Fix :meth:`~Series.str.isdigit` to correctly recognize unicode superscript
characters as digits for :class:`StringDtype` backed by PyArrow (:issue:`61466`)

.. ---------------------------------------------------------------------------
.. _whatsnew_232.contributors:
Expand Down
7 changes: 7 additions & 0 deletions pandas/core/arrays/_arrow_string_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
HAS_PYARROW,
pa_version_under13p0,
pa_version_under17p0,
pa_version_under21p0,
)

if HAS_PYARROW:
Expand Down Expand Up @@ -261,6 +262,12 @@ def _str_isdecimal(self):
return self._convert_bool_result(result)

def _str_isdigit(self):
if pa_version_under21p0:
# https://github.com/pandas-dev/pandas/issues/61466
res_list = self._apply_elementwise(str.isdigit)
return self._convert_bool_result(
pa.chunked_array(res_list, type=pa.bool_())
)
result = pc.utf8_is_digit(self._pa_array)
return self._convert_bool_result(result)

Expand Down
7 changes: 4 additions & 3 deletions pandas/tests/strings/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,9 @@ def test_ismethods(method, expected, any_string_dtype):
@pytest.mark.parametrize(
"method, expected",
[
("isnumeric", [False, True, True, False, True, True, False]),
("isdecimal", [False, True, False, False, False, True, False]),
("isnumeric", [False, True, True, True, False, True, True, False]),
("isdecimal", [False, True, False, False, False, False, True, False]),
("isdigit", [False, True, True, False, False, False, True, False]),
],
)
def test_isnumeric_unicode(method, expected, any_string_dtype):
Expand All @@ -250,7 +251,7 @@ def test_isnumeric_unicode(method, expected, any_string_dtype):
# 0x1378: ፸ ETHIOPIC NUMBER SEVENTY
# 0xFF13: 3 Em 3 # noqa: RUF003
ser = Series(
["A", "3", "¼", "★", "፸", "3", "four"], # noqa: RUF001
["A", "3", "³", "¼", "★", "፸", "3", "four"], # noqa: RUF001
dtype=any_string_dtype,
)
expected_dtype = (
Expand Down
Loading