Description
Problem
When submitting traversals including float values, the GraphSON-serialized traversal truncates them:
g.V().has("id", "X").property("popularity", 0.099999).iterate()
is serialized to
{"gremlin":{"@type":"g:Bytecode","@value":{"source":[],"step":[["V"],["has","id","X"],["property","popularity",{"@type":"g:Double","@value":0.1}],["none"]]}},"processor":"traversal"}
Cause
In gremlin_python/driver/serializer.py (but also protocol.py in passing), ujson is imported in place of stdlib json:
try: import ujson as json except ImportError: import json
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):
ujson.dumps(0.099999) == '0.1'
With ujson >= 2.0, out-of-the-box floating point precision was improved:
ujson.dumps(0.099999) == '0.099999'
Here is the change in ujson explaining the difference: ultrajson/ultrajson@eb7d894
Potential solution
Could ujson be listed as an optional dependency in setup.py with version >= 2.0 ?