rows
rows copied to clipboard
WIP: Fix float conversion
As described in #198:
- the attempt detect the type of
'1.0'(a string) would (correctly) suggestFloatField - but the attempt do detect the type of
1.0(a float) would (wrongly) suggestIntegerField
This was probably due to this comparison in the IntegerField.deserialize method:
…
elif isinstance(value, float):
new_value = int(value)
if new_value != value:
…
As indeed 1 == 1.0, this might be causing the wrongly type detection. Thus I'm suggesting is instead — in other words 1 == 1.0 passes, but 1 is 1.0 doesn't.
That fixes the issues and make tests suggested in the issue pass ; )
There's a problem in this PR. This PR brakes test_IntegerField (test_fields.py) in this assertion:
self.assertEqual(fields.IntegerField.deserialize(42.0), 42)
It makes sense to convert 42.0 as a float when using detect_type, but is user specifies IntegerField then IntegerField.deserialize(42.0) should return 42. Is there something in the API to know, at the point of deserializing, if the method was called from detect_type?