Fix get_integer_time precision and zero handling#494
Fix get_integer_time precision and zero handling#494Saptami191 wants to merge 4 commits intomllam:mainfrom
Conversation
|
@joeloskarsson Recreated this PR after fixing earlier issues with the template and workflow. The code, tests, and linting are now clean and aligned with project guidelines. Would appreciate a review. |
kshirajahere
left a comment
There was a problem hiding this comment.
I think the integer-microseconds direction is the right fix, but I think there is still few thing worth addressing before merge.
| (0, 'seconds') | ||
| """ | ||
| total_seconds = tdelta.total_seconds() | ||
| total_microseconds = ( |
There was a problem hiding this comment.
The new implementation is fine, but this helper’s contract is still inconsistent across the tree: compute_standardization_stats.py still calls get_integer_time(step_length.total_seconds()), i.e. with a float rather than a timedelta. I think we should either update that caller in the same slice or explicitly tighten/document the contract here.
| assert get_integer_time(timedelta(0)) == (0, "seconds") | ||
|
|
||
|
|
||
| def test_milliseconds(): |
There was a problem hiding this comment.
Since this PR is specifically about float-precision avoidance, I think it would be good to add one direct regression test for the issue-body example (timedelta(days=0.001) -> (86400, "milliseconds")) here as well, rather than leaving that behavior covered only by the doctest.
There was a problem hiding this comment.
This is actually already tested in the docstring.
CHANGELOG.md
Outdated
|
|
||
| - Fix typo in `ar_model.py` that causes `AttributeError` during evaluation [\#204](https://github.com/mllam/neural-lam/pull/204) @ritinikhil | ||
|
|
||
| - Fix `get_integer_time` to avoid floating-point precision issues and correctly handle zero timedelta [#469](https://github.com/mllam/neural-lam/pull/469) @Saptami191 |
There was a problem hiding this comment.
Thanks for the review! I hve addressed all three points.
observingClouds
left a comment
There was a problem hiding this comment.
Thanks for this PR. I left a few comments and suggest a few changes.
| assert get_integer_time(timedelta(0)) == (0, "seconds") | ||
|
|
||
|
|
||
| def test_milliseconds(): |
There was a problem hiding this comment.
This is actually already tested in the docstring.
There was a problem hiding this comment.
All these newly added tests are already covered by the doctest. No need to replicate them here. If you think a case is missing in the docstring, please add them there.
There was a problem hiding this comment.
@observingClouds thanks for the review! yeah all are tested in docstring. i will remove this test file .actually it was part of proving the fix is correct.
Should I also add a doctest for negative timedelta
get_integer_time(timedelta(days=-7))
(-1, 'weeks')
it will represent a duration in the past 7 days ago.
or is that out of scope for this PR?
Describe your changes
Fix get_integer_time precision issues and zero timedelta handling.
Uses integer microseconds instead of float computation to avoid rounding errors and ensure correct unit detection.
No additional dependencies.
Issue Link
Closes #468
Type of change
Checklist before requesting a review
pullwith--rebaseoption if possible).Checklist for reviewers
Each PR comes with its own improvements and flaws. The reviewer should check the following:
Author checklist after completed review
reflecting type of change:
Checklist for assignee