Clément de Groc created TINKERPOP-2631:
------------------------------------------
Summary: GraphSON float serialization when ujson is used is
imprecise
Key: TINKERPOP-2631
URL: https://issues.apache.org/jira/browse/TINKERPOP-2631
Project: TinkerPop
Issue Type: Improvement
Components: python
Affects Versions: 3.5.1
Reporter: Clément de Groc
h1. Problem
When submitting traversals including float values, the GraphSON-serialized
traversal truncates them:
{code:java}
g.V().has("id", "X").property("popularity", 0.099999).iterate(){code}
is serialized to
{code:java}
{"gremlin":{"@type":"g:Bytecode","@value":{"source":[],"step":[["V"],["has","id","X"],["property","popularity",{"@type":"g:Double","@value":0.1}],["none"]]}},"processor":"traversal"}
{code}
h1. Cause
In
{{[gremlin_python/driver/serializer.py|https://github.com/apache/tinkerpop/blob/master/gremlin-python/src/main/python/gremlin_python/driver/serializer.py#L19-L22]}}
(but also {{protocol.py}} in passing), {{ujson}} is imported in place of
stdlib {{json}}:
{code:java}
try:
import ujson as json
except ImportError:
import json
{code}
This is certainly done for performance reasons, but this has an impact on
floating point precision.
With {{ujson <}} 2.0, if \{{precise_float }}is not specified (which is the
case):
{code:java}
ujson.dumps(0.099999) == '0.1'{code}
With {{ujson}} >= 2.0, out-of-the-box floating point precision was improved:
{code:java}
ujson.dumps(0.099999) == '0.099999'{code}
Here is the change in ujson explaining the difference:
[ultrajson/ultrajson@{{eb7d894}}|https://github.com/ultrajson/ultrajson/commit/eb7d894f225bb89d269188ba6ec559b914a71b8a]
h1. Potential solution
Could {{ujson}} be listed as an optional dependency in {{setup.py}} with
version >= 2.0 ?
--
This message was sent by Atlassian Jira
(v8.3.4#803005)