Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v1.1.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Bug fixes
- Bug in :meth:`Series.dt.isocalendar` and :meth:`DatetimeIndex.isocalendar` that returned incorrect year for certain dates (:issue:`36032`)
- Bug in :class:`DataFrame` indexing returning an incorrect :class:`Series` in some cases when the series has been altered and a cache not invalidated (:issue:`33675`)
- Bug in :meth:`DataFrame.corr` causing subsequent indexing lookups to be incorrect (:issue:`35882`)
- Bug in :func:`to_numeric` where precision was incorrect (:issue:`31364`)

.. ---------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion pandas/_libs/src/parse_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ int to_double(char *item, double *p_value, char sci, char decimal,
char *p_end = NULL;
int error = 0;

*p_value = xstrtod(item, &p_end, decimal, sci, '\0', 1, &error, maybe_int);
/* Switch to precise xstrtod GH 31364 */
*p_value = precise_xstrtod(item, &p_end, decimal, sci, '\0', 1,
&error, maybe_int);

return (error == 0) && (!*p_end);
}
Expand Down
7 changes: 7 additions & 0 deletions pandas/tests/tools/test_to_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,10 @@ def test_failure_to_convert_uint64_string_to_NaN():
ser = Series([32, 64, np.nan])
result = to_numeric(pd.Series(["32", "64", "uint64"]), errors="coerce")
tm.assert_series_equal(result, ser)


def test_precision():
# GH 31364
result = to_numeric("243.164")

assert result == 243.164