Skip to content

fix: preserve days and formatting in TimeDeltaSerializer._to_dict_value - #79

Open
reginaldalfret wants to merge 1 commit into
Kaggle:mainfrom
reginaldalfret:fix/timedelta-serializer-preserve-days
Open

reginaldalfret wants to merge 1 commit into
Kaggle:mainfrom
reginaldalfret:fix/timedelta-serializer-preserve-days

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

This PR addresses #73 by fixing the serialization of timedelta instances in TimeDeltaSerializer._to_dict_value.

Problem

  1. TimeDeltaSerializer._to_dict_value previously used delta.seconds, which only returns the seconds component (0..86399) modulo 86400, discarding delta.days. Any duration of one day or more (such as a 30-hour quota: 108000s) was incorrectly serialized as "21600s" (6 hours).
  2. _nanos_to_str used float division (/), producing strings like "735.0" which raised a ValueError when parsed back in _from_dict_value. Sub-second values like 5ms also omitted leading zeros, serializing as "0.5s" instead of "0.005s".

Solution

  • Calculate total microseconds taking into account both delta.days and delta.seconds.
  • Use integer division and zero-padding in _nanos_to_str matching the Protobuf JSON duration specification (3, 6, or 9 digits).
  • Added comprehensive unit tests in kaggle_object_tests.py verifying durations with days, fractional seconds, microsecond zero-padding, and full round-trip serialization/deserialization.

Closes #73

Calculate total seconds from both days and seconds so durations >= 1 day
are not truncated modulo 86400s. Fix nanos division and zero-padding so
fractional second strings conform to protobuf JSON duration format and
round-trip cleanly through _from_dict_value.

Closes Kaggle#73
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TimeDeltaSerializer._to_dict_value drops the days of a timedelta (108000 s serialized as "21600s")

1 participant