Skip to content

RethinkDB converts float 0.0 to int 0 #263

@EugeniuZ

Description

@EugeniuZ

Hi,

Seems that RethinkDB is converting float value of 0.0 to integer value of 0.
In my scenario the problem is that python dictionaries are saved in RethinkDB and upon retrieval this (undesired) conversion happens. Some of the upstream systems check for the type of the field (float is expected but an int is received).

Is there a way to avoid this conversion? Is it a feature or a bug?

task_info = {'a': 0.0, 'b': +0.0, 'c': -0.0}
ta = task_info['a']
tb = task_info['b']
tc = task_info['c']
print(f'ta - {type(ta)}, {ta}')
print(f'tb - {type(tb)}, {tb}')
print(f'tc - {type(tc)}, {tc}')
result = r.table(table).insert(task_info).run(connection)
task_id = result['generated_keys'][0]

Output is:

ta - <class 'float'>, 0.0
tb - <class 'float'>, 0.0
tc - <class 'float'>, -0.0
document = r.table(table).get(task_id).run(connection)
print(document)
a = document['a']
b = document['b']
c = document['c']
print(f'a - {type(a)}, {a}')
print(f'b - {type(b)}, {b}')
print(f'b - {type(c)}, {c}')

Output is:

{'a': 0, 'b': 0, 'c': -0.0, 'id': 'd8df59a5-330f-4cd0-84ac-394b70a05b9d'}
a - <class 'int'>, 0
b - <class 'int'>, 0
b - <class 'float'>, -0.0

Using the latest container (rethinkdb 2.4.1~0buster)
Python client version (rethinkdb==2.4.8)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy