Skip to content

Fix failure to convert string "uint64" to NaN #32541

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

Merged
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ Timezones
Numeric
^^^^^^^
- Bug in :meth:`DataFrame.floordiv` with ``axis=0`` not treating division-by-zero like :meth:`Series.floordiv` (:issue:`31271`)
-
- Bug in :meth:`to_numeric` with string argument ``"uint64"`` and ``errors="coerce"`` silently fails (:issue:`32394`)
-

Conversion
Expand Down
2 changes: 0 additions & 2 deletions pandas/_libs/lib.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2024,8 +2024,6 @@ def maybe_convert_numeric(ndarray[object] values, set na_values,
except (TypeError, ValueError) as err:
if not seen.coerce_numeric:
raise type(err)(f"{err} at position {i}")
elif "uint64" in str(err): # Exception from check functions.
raise

seen.saw_null()
floats[i] = NaN
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,13 @@ def test_convert_numeric_int64_uint64(self, case, coerce):
result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
tm.assert_almost_equal(result, expected)

def test_convert_numeric_string_uint64(self):
# GH32394
result = lib.maybe_convert_numeric(
np.array(["uint64"], dtype=object), set(), coerce_numeric=True
)
assert np.isnan(result)
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not a good test - does it replicate what the OP was? this is not user facing at all

pls follow what is going on in other tests

Copy link
Contributor

Choose a reason for hiding this comment

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

The OP currently takes this path, though it'd be good to test at the pd.to_numeric level too.


@pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64])
def test_convert_int_overflow(self, value):
# see gh-18584
Expand Down