-
-
Notifications
You must be signed in to change notification settings - Fork 629
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
Support serialization as float in TimeDelta field #1998
Support serialization as float in TimeDelta field #1998
Conversation
Able to (de)serialise to float values as a representation of the total seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution.
I understand your use case.
I'm reluctant to integrate this as is, though. At this point, we might as well offer int and float for any precision. This would have the benefit of symmetry, the possibilities would be the cartesian product of {all precisions} x {int, float}. And one could serialize to a floating point number of days.
You'd just have to add a new parameter expressing int or float (int by default).
Just my thoughts, I could be convinced otherwise and maybe other maintainers will chime in with a different view.
Having a |
Went ahead and updated anyway to support all precisions through use of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, thanks!
Just minor comments.
- Implement a test for exception being raised on invalid type parameter. - Rename serde_type to serialization_type. - Condense code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just a few comments.
I'll wait a few days in case other maintainers want to review as well.
Fixed up remaining documentation issues. |
Add functionality to (de)serialize to float values as a representation of the total seconds.
In our use case, we are trying to specify a period which is a combination of seconds, milliseconds and microseconds, which is easier to represent as a single floating point value rather than specifying the smallest unit (microseconds). We have currently been serializing to a
fields.Float()
using.total_seconds()
and the equivalent to deserialize.The feature does not promise absolute precision, which is stated in the docs (same restrictions as floating point values).
This does not change the current way
TimeDelta
is used.