rows icon indicating copy to clipboard operation
rows copied to clipboard

WIP: Fix float conversion

Open cuducos opened this issue 8 years ago • 1 comments

As described in #198:

  • the attempt detect the type of '1.0' (a string) would (correctly) suggest FloatField
  • but the attempt do detect the type of 1.0 (a float) would (wrongly) suggest IntegerField

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 ; )

cuducos avatar Oct 15 '17 14:10 cuducos

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?

cuducos avatar Nov 01 '17 22:11 cuducos