Skip to content

Commit a3985f8

Browse files
Fix failure to convert string "uint64" to NaN (#32541)
1 parent edb863e commit a3985f8

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

doc/source/whatsnew/v1.1.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ Timezones
231231
Numeric
232232
^^^^^^^
233233
- Bug in :meth:`DataFrame.floordiv` with ``axis=0`` not treating division-by-zero like :meth:`Series.floordiv` (:issue:`31271`)
234-
-
234+
- Bug in :meth:`to_numeric` with string argument ``"uint64"`` and ``errors="coerce"`` silently fails (:issue:`32394`)
235235
-
236236

237237
Conversion

pandas/_libs/lib.pyx

-2
Original file line numberDiff line numberDiff line change
@@ -2024,8 +2024,6 @@ def maybe_convert_numeric(ndarray[object] values, set na_values,
20242024
except (TypeError, ValueError) as err:
20252025
if not seen.coerce_numeric:
20262026
raise type(err)(f"{err} at position {i}")
2027-
elif "uint64" in str(err): # Exception from check functions.
2028-
raise
20292027

20302028
seen.saw_null()
20312029
floats[i] = NaN

pandas/tests/dtypes/test_inference.py

+7
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,13 @@ def test_convert_numeric_int64_uint64(self, case, coerce):
507507
result = lib.maybe_convert_numeric(case, set(), coerce_numeric=coerce)
508508
tm.assert_almost_equal(result, expected)
509509

510+
def test_convert_numeric_string_uint64(self):
511+
# GH32394
512+
result = lib.maybe_convert_numeric(
513+
np.array(["uint64"], dtype=object), set(), coerce_numeric=True
514+
)
515+
assert np.isnan(result)
516+
510517
@pytest.mark.parametrize("value", [-(2 ** 63) - 1, 2 ** 64])
511518
def test_convert_int_overflow(self, value):
512519
# see gh-18584

0 commit comments

Comments
 (0)