From 9f409762d9d096892a57a29cb05f921f4f6a02c8 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 5 Sep 2020 16:48:37 -0400 Subject: [PATCH 1/4] BUG: fix precision issue with to_numeric --- doc/source/whatsnew/v1.1.2.rst | 2 +- pandas/_libs/src/parse_helper.h | 3 ++- pandas/tests/tools/test_to_numeric.py | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.2.rst b/doc/source/whatsnew/v1.1.2.rst index d1a66256454ca..ba22ad680525b 100644 --- a/doc/source/whatsnew/v1.1.2.rst +++ b/doc/source/whatsnew/v1.1.2.rst @@ -36,7 +36,7 @@ Bug fixes - Bug in :meth:`Float64Index.__contains__` incorrectly raising ``TypeError`` instead of returning ``False`` (:issue:`35788`) - 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 :func:`to_numeric` where precision was incorrect (:issue:`31364`) .. --------------------------------------------------------------------------- .. _whatsnew_112.other: diff --git a/pandas/_libs/src/parse_helper.h b/pandas/_libs/src/parse_helper.h index 2ada0a4bd173d..90bfd1c774ad7 100644 --- a/pandas/_libs/src/parse_helper.h +++ b/pandas/_libs/src/parse_helper.h @@ -18,7 +18,8 @@ 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); } diff --git a/pandas/tests/tools/test_to_numeric.py b/pandas/tests/tools/test_to_numeric.py index 263887a8ea36e..813457612f989 100644 --- a/pandas/tests/tools/test_to_numeric.py +++ b/pandas/tests/tools/test_to_numeric.py @@ -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 From ea2b93c47c55c4b46ee6b8765eeacc6ddf152812 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Sat, 5 Sep 2020 17:42:04 -0400 Subject: [PATCH 2/4] fix lint issue in parse_helper.h --- pandas/_libs/src/parse_helper.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandas/_libs/src/parse_helper.h b/pandas/_libs/src/parse_helper.h index 90bfd1c774ad7..d161c4e29fe15 100644 --- a/pandas/_libs/src/parse_helper.h +++ b/pandas/_libs/src/parse_helper.h @@ -19,7 +19,8 @@ int to_double(char *item, double *p_value, char sci, char decimal, int error = 0; /* Switch to precise xstrtod GH 31364 */ - *p_value = precise_xstrtod(item, &p_end, decimal, sci, '\0', 1, &error, maybe_int); + *p_value = precise_xstrtod(item, &p_end, decimal, sci, '\0', 1, + &error, maybe_int); return (error == 0) && (!*p_end); } From b3911d0c0e311f5fcb75495b64626e26f0322d87 Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Tue, 8 Sep 2020 07:56:46 -0400 Subject: [PATCH 3/4] remove doc/example.feather --- doc/example.feather | Bin 1120 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 doc/example.feather diff --git a/doc/example.feather b/doc/example.feather deleted file mode 100644 index 38dbf087a1590606ae40aaab16fd2d592b771b0e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1120 zcmZuxyGlbr5S^R5Nz{a}NW>HtK_sM7>|!IaNGdxCSXd;{_yCQdR#tw3l~`I>OA5ci zQbZ6$tgQTs#B+9c!YinJCM9>)^273K{XQhooJB2<^&GtHH$(bNO86J_M!J zyGzt-fVTu_y`vB(l0%(5PA9RI8omTJPF`^*F6IUYC9RG~2~6L$#r{j48ZpBzkgR*? zeK=XyxVoIL>-SgCJxtfJc!iX{qHf5i{ID};{XtI7TL*ORLEuwa*BRfN-m;sO{Zgj$ ztzwsCRRGO(Kw^-p-}PKGd}}=UlwnHzzIVB^>*KSHVAFV==PAS|XXz*6tt_YQ$5f~C oX+L~3>;6heD7rV}T*>^s5KCq8YfagILHpBwHUBLPZTxTf15K=C=l}o! From 2b7fe2bd2ef38202200c57d7b00b2c3369b5cf3a Mon Sep 17 00:00:00 2001 From: Irv Lustig Date: Tue, 8 Sep 2020 07:58:33 -0400 Subject: [PATCH 4/4] from 1.1.2 to 1.2 --- doc/source/whatsnew/v1.1.2.rst | 1 - doc/source/whatsnew/v1.2.0.rst | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/source/whatsnew/v1.1.2.rst b/doc/source/whatsnew/v1.1.2.rst index bde0143540420..a214ad9762733 100644 --- a/doc/source/whatsnew/v1.1.2.rst +++ b/doc/source/whatsnew/v1.1.2.rst @@ -43,7 +43,6 @@ Bug fixes - 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 :meth:`import_optional_dependency` returning incorrect package names in cases where package name is different from import name (:issue:`35948`) -- Bug in :func:`to_numeric` where float precision was incorrect (:issue:`31364`) .. --------------------------------------------------------------------------- diff --git a/doc/source/whatsnew/v1.2.0.rst b/doc/source/whatsnew/v1.2.0.rst index 2afa1f1a6199e..2aac2596c18cb 100644 --- a/doc/source/whatsnew/v1.2.0.rst +++ b/doc/source/whatsnew/v1.2.0.rst @@ -245,7 +245,7 @@ Timezones Numeric ^^^^^^^ -- +- Bug in :func:`to_numeric` where float precision was incorrect (:issue:`31364`) - Conversion