Repository navigation
Test: Cover untested datetime micros/nanos converters - #4501
Merged
Fokko merged 1 commit intoNov 30, 2026
Merged
Conversation
Contributor
Author
|
Hello @Fokko and @rambleraptor could you please review the changes I have made ! |
Add unit tests for datetime helper functions that had no coverage: micros_to_time, micros_to_timestamptz, micros_to_hours, and the nanos_to_* family (timestamp, time, days, months, years). These power the partition transforms and were previously untested.
prabhleen2317
force-pushed
the
datetime-converter-test-coverage
branch
from
November 27, 2026 11:12
ae42a11 to
354664f
Compare
Fokko
approved these changes
Nov 30, 2026
Fokko
left a comment
Contributor
There was a problem hiding this comment.
Thanks @prabhleen2317, the expected values all check out! A couple of suggestions that could go in a follow-up:
- The interesting behavior in these helpers is the floor/truncation, which the current cases don't exercise:
nanos_to_time/nanos_to_timestamptruncate sub-microsecond precision, but all inputs end in000. Something like73_304_375_612_999 → time(20, 21, 44, 375612)would cover it.nanos_to_timestamp(-1)should floor todatetime(1969, 12, 31, 23, 59, 59, 999999), mirroring the negative case intest_nanos_to_micros.micros_to_time(86_399_999_999) → time(23, 59, 59, 999999)would cover the end-of-day boundary.
- In
test_micros_to_timestamptz, aware datetimes compare by instant, so equality alone wouldn't catch a non-UTCtzinfo. Addingassert micros_to_timestamptz(micros).tzinfo == UTCwould pin that down.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds unit tests for datetime helper functions in
pyiceberg/utils/datetime.pythat previously had no coverage:
micros_to_time,micros_to_timestamptz,micros_to_hours, and thenanos_to_*family (timestamp,time,days,months,years).Closes #4500.
Test plan
make test PYTEST_ARGS="-k datetime"— 87 passedruff check/ruff formatclean