Uploaded image for project: 'TinkerPop'
  1. TinkerPop
  2. TINKERPOP-2631

GraphSON float serialization when ujson is used is imprecise

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.5.1
    • 3.7.0, 3.6.1, 3.5.4
    • python
    • None

    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 ?

      Attachments

        Activity

          People

            lyndonb Lyndon Bauto
            cdegroc Clément de Groc
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: