Skip to content

Test: Cover untested datetime micros/nanos converters - #4501

Merged
Fokko merged 1 commit into
apache:mainfrom
prabhleen2317:datetime-converter-test-coverage
Nov 30, 2026
Merged

Fokko merged 1 commit into
apache:mainfrom
prabhleen2317:datetime-converter-test-coverage

Conversation

@prabhleen2317

Copy link
Copy Markdown
Contributor

Summary

Adds unit tests for datetime helper functions in pyiceberg/utils/datetime.py
that previously had no coverage: micros_to_time, micros_to_timestamptz,
micros_to_hours, and the nanos_to_* family (timestamp, time, days,
months, years).

Closes #4500.

Test plan

  • make test PYTEST_ARGS="-k datetime" — 87 passed
  • ruff check / ruff format clean

@prabhleen2317

Copy link
Copy Markdown
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
prabhleen2317 force-pushed the datetime-converter-test-coverage branch from ae42a11 to 354664f Compare November 27, 2026 11:12

@Fokko Fokko left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @prabhleen2317, the expected values all check out! A couple of suggestions that could go in a follow-up:

  1. The interesting behavior in these helpers is the floor/truncation, which the current cases don't exercise:
    • nanos_to_time / nanos_to_timestamp truncate sub-microsecond precision, but all inputs end in 000. Something like 73_304_375_612_999 → time(20, 21, 44, 375612) would cover it.
    • nanos_to_timestamp(-1) should floor to datetime(1969, 12, 31, 23, 59, 59, 999999), mirroring the negative case in test_nanos_to_micros.
    • micros_to_time(86_399_999_999) → time(23, 59, 59, 999999) would cover the end-of-day boundary.
  2. In test_micros_to_timestamptz, aware datetimes compare by instant, so equality alone wouldn't catch a non-UTC tzinfo. Adding assert micros_to_timestamptz(micros).tzinfo == UTC would pin that down.

@Fokko
Fokko added this pull request to the merge queue Nov 30, 2026
Merged via the queue into apache:main with commit 4ed9478 Nov 30, 2026
20 checks passed
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.

Missing unit test coverage for datetime micros/nanos converter helpers

2 participants