Skip to content

another to_json float precision bug #15864

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

Closed
funnycrab opened this issue Apr 2, 2017 · 2 comments
Closed

another to_json float precision bug #15864

funnycrab opened this issue Apr 2, 2017 · 2 comments
Labels
IO JSON read_json, to_json, json_normalize
Milestone

Comments

@funnycrab
Copy link
Contributor

funnycrab commented Apr 2, 2017

Code Sample, a copy-pastable example if possible

>>> pd.DataFrame([dict(a_float=0.95)]).to_json(double_precision=1)
'{"a_float":{"0":0.1}}'
>>> pd.DataFrame([dict(a_float=1.95)]).to_json(double_precision=1)
'{"a_float":{"0":1.1}}'
 >>> pd.DataFrame([dict(a_float=-1.95)]).to_json(double_precision=1)
'{"a_float":{"0":-1.1}}'
>>> pd.DataFrame([dict(a_float=0.995)]).to_json(double_precision=2)
'{"a_float":{"0":0.1}}'
>>> pd.DataFrame([dict(a_float=0.9995)]).to_json(double_precision=3)
'{"a_float":{"0":0.1}}'

Problem description

This issue is very similar to #15716.

Just this one reveals a more generalized pattern.

Expected Output

'{"a_float":{"0":1.0}}'
'{"a_float":{"0":2.0}}'
'{"a_float":{"0":-2.0}}'
'{"a_float":{"0":1.0}}'
'{"a_float":{"0":1.0}}'

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.5.2.final.0 python-bits: 64 OS: Linux OS-release: 3.19.0-42-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_HK.UTF-8 LOCALE: en_HK.UTF-8

pandas: 0.19.2
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.3
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.2
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None

funnycrab pushed a commit to funnycrab/pandas that referenced this issue Apr 2, 2017
This is a fix attempt for issue pandas-dev#15716 as well as pandas-dev#15864.

Note that whenever the frac is incremented, there is a chance that its
value may hit the value of pow10.
@funnycrab
Copy link
Contributor Author

After a quick check, I believe this issue may not be related to here as pointed out in the #15716.

It seems to have something to do with rollover handling implemented here.

A pull request has been submitted for fixing this issue. Please be so kind as to take a look.

@jreback
Copy link
Contributor

jreback commented Apr 2, 2017

these seem almost the same, simply roll them together.

@jreback jreback closed this as completed Apr 2, 2017
@jreback jreback added the IO JSON read_json, to_json, json_normalize label Apr 2, 2017
@jreback jreback added this to the No action milestone Apr 2, 2017
@jreback jreback modified the milestones: 0.20.0, No action Apr 3, 2017
jreback pushed a commit that referenced this issue Apr 3, 2017
closes #15716
closes #15864

whenever the frac is incremented, there is a chance that its  value
may hit the value of pow10.

Author: funnycrab <[email protected]>
Author: Funnycrab <Funnycrab>

Closes #15865 from funnycrab/fix_rollover_handling_in_json_enc and squashes the following commits:

c9710ee [funnycrab] add more tests for examples listed in issue #15716 and #15864
3cee6b3 [funnycrab] add whatsnew entry
9b0dff0 [funnycrab] remove additional blank line
75effb4 [funnycrab] add tests
6acb969 [funnycrab] fix for cpplint
aec58e6 [Funnycrab] BUG: Fix rollover handling in json encoding
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
IO JSON read_json, to_json, json_normalize
Projects
None yet
Development

No branches or pull requests

2 participants