Skip to content
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
12 changes: 11 additions & 1 deletion pandas/core/strings/object_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,17 @@ def _str_islower(self):
return self._str_map(str.islower, dtype="bool")

def _str_isnumeric(self):
return self._str_map(str.isnumeric, dtype="bool")
def is_numeric(value):
if value.isnumeric():
return True
else:
try:
float(value) # Try converting to float (supports negative and decimals)
return True
except ValueError:
return False

return self._str_map(is_numeric, dtype="bool")
Comment on lines +471 to +481

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am negative on this change. As mentioned in the issue, I do not believe we should be changing the behavior of is_numeric here.

pandas-dev#60750 (comment)
pandas-dev#60750 (comment)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize this was a PR in your fork - apologies. However, if you do want to contribute to pandas, you need to open up a PR in the pandas repository and not your fork of it.


def _str_isspace(self):
return self._str_map(str.isspace, dtype="bool")
Expand Down
6 changes: 3 additions & 3 deletions pandas/tests/strings/test_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,8 @@ 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, False, True, True, False, True, True]),
("isdecimal", [False, True, False, False, False, True, False, True, True]),
],
)
def test_isnumeric_unicode(method, expected, any_string_dtype):
Expand All @@ -250,7 +250,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", "1.2", "0.0"], # noqa: RUF001
dtype=any_string_dtype,
)
expected_dtype = (
Expand Down