-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
BUG: conversion of float32 to string shows too much precision #36451
Comments
Correction: the above behaviour is on released 1.1.0, and on 1.1.2 and master we have this bug for
|
ref #35519 which I think caused the regression for str |
This is a bit odd, seems like a straight str conversion (as is done in #35519) should work right: >>> str(np.float64(0.1))
0.1 # ok
str(np.float32(0.1))
0.1 # ok But I see the function added in #35519 gives a different string: >>> f64 = np.array([0.1], dtype="float64")
>>> pd._libs.lib.ensure_string_array(f64)
array(['0.1'], dtype=object) # ok
>>> f32 = np.array([0.1], dtype="float32")
>>> pd._libs.lib.ensure_string_array(f32)
array(['0.10000000149011612'], dtype=object) # not ok so something in EDIT: I can see @dsaxton has already figured it out and pushed a PR, Thanks! |
Ah, so the difference is:
(because converting to object dtype converts to builtin float type) So I suppose because float32 has less precision, the stdlib float shows those decimals. While the numpy.float32 behaves more as we want. |
On master (but also on 1.1):
When converting to the object-dtype string, it works as expected:
cc @topper-123
The text was updated successfully, but these errors were encountered: