Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Fix float conversion #258

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rows/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def deserialize(cls, value, *args, **kwargs):
return value
elif isinstance(value, float):
new_value = int(value)
if new_value != value:
if not new_value is value: # we want 1.0 to be different from 1
raise ValueError("It's float, not integer")
else:
value = new_value
Expand Down
13 changes: 13 additions & 0 deletions tests/tests_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,19 @@ def test_detect_types_binary(self):
result = fields.detect_types(self.fields, values)
self.assertDictEqual(dict(result), expected)

def test_detect_types_float_int(self):
'''detect_types must preserve object type

From issue: https://github.com/turicas/rows/issues/198
'''

field_names = ['field1', 'field2']
expected = {'field1': fields.IntegerField,
'field2': fields.FloatField, }

assert expected == fields.detect_types(field_names, [[42, 1.2]])
assert expected == fields.detect_types(field_names, [[42, 1.0]])

def test_detect_types(self):
result = fields.detect_types(self.fields, self.data)
self.assertDictEqual(dict(result), self.expected)
Expand Down