Open bytelinker opened 4 months ago
can I investigate this issue?
Thanks for the report. I think the first line using exponential notation is a duplicate of #23328. It seems to me the intended behavior of to_json is to remove any information after what is specified by double_precision
. This would mean a request to not do so is a feature enhancement.
Thank you for the answer. When writing a "test_values = 1.2345678901234567890 * 10 ** exponents" to json and getting back for example 0.000000000000001 this is an error of approx 23.4 %. The digits after 1 = 234567..... are missing. Can this be changed by using other options in the actual version, please? But as it can be done without a warning I would consider this as a bug.
Hello bigrogerio,
Of course you can investigate this issue.
Can this be changed by using other options in the actual version, please?
Not that I am aware of.
But as it can be done without a warning I would consider this as a bug.
From what I can tell, this seems to be the intended design. If there is any indication to the contrary, then I would agree it is a bug. However if it is indeed the intended design, then what you are asking for is an API/behavior change rather than a bugfix.
Using floats in pandas is a common uses case. When saving these floats to a json and loading them again, a lo of precision is lost. Much more than can be expected. I can't see why this is the intended behavior.
Pandas version checks
[X] I have checked that this issue has not already been reported.
[X] I have confirmed this bug exists on the latest version of pandas.
[X] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
the floats written to json have got a fixed length, the last digits are truncated. so precision is lost. the floats could be converted to scientific notation so no precision would be lost.
possible code for issue: https://github.com/pandas-dev/pandas/blob/main/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c https://github.com/pandas-dev/pandas/blob/63dc1bb4f99d24b46bacb113d740d54459fdbe5e/pandas/_libs/src/vendored/ujson/lib/ultrajsonenc.c#L818
Expected Behavior
convert floats to scientific notation in json
Installed Versions