-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Rounding on float16 type not working #35124
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
Comments
we have very little support for float16 furthermore i suspect this is really just a display issue; convert the series to numpy and see |
Hello! |
This is actually the case. Converting it back to numpy gives us the correct result, so the values underneath are actually rounded correct:
|
Thank you! When I save in CSV format it was 4 decimals truncated as expected. But now I found a use case where it's not working: df = pd.DataFrame(np.array([0.37324, 0.12321, 0.23]), columns=['A'])
df.astype(np.float16).round(4).to_dict('records') Outputs Also important: the same problem occurs with float32. The float64 and float128 types don't present the problem. Please, consider re-open the issue as the examples I gave are the commonly used way to work with Pandas and PyMongo. We could iterate over all the dict, but that's not the idea. Thanks in advance |
Can confirm the problem stated above occurs on master as well. @jreback would that be sufficient to re-open this issue? |
Maybe important to note that
|
@jreback Is there any update on this? If you like i would try making a PR when I have some free time. |
you can make a PR but really sure what you are attempting to solve |
Ok, I'll try in a few weeks |
Hi, The issue is still present on the latest release of pandas with float32. Regards, |
you would have to open a new issue with a reproducible example |
Hi Jeff, I don't know ! This issue was reproducible, clear and ... closed with no action. The best I can do here is to inform you, then cast my series to float64 and move on. No hard feelings here, I'm glad this bug was reported because I know why it's not working as I expected. Regards, |
this is about float16 |
Now it's about float16 and float32 :'D |
I found the root cause: #50125 (comment) |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
(optional) I have confirmed this bug exists on the master branch of pandas.
Problem description
I'm trying to round a column to 4 decimal places to store them in the DB. I must use
np.float16
type to work with as I need the smallest possible precision, but it's not working (see output section), if I don't cast the values and leave them asnp.float64
type It'll work correctly.I think it's a bug of Pandas as if I run:
It works as expected, so It doesn't seem to be a problem for Numpy.
Code Sample
Running:
Doesn't work either as it has the same output.
Current Output
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : None
python : 3.7.5.final.0
python-bits : 64
OS : Linux
OS-release : 5.3.0-62-generic
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : es_AR.UTF-8
LOCALE : es_AR.UTF-8
pandas : 1.0.5
numpy : 1.18.1
pytz : 2019.3
dateutil : 2.8.1
pip : 18.1
setuptools : 40.8.0
Cython : None
pytest : 5.3.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 2.11.1
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pytables : None
pytest : 5.3.5
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
xlsxwriter : None
numba : None
The text was updated successfully, but these errors were encountered: