Preserve nanosecond precision in Python dataset construction - #8406
Open
sophianggan wants to merge 1 commit into
Open
Preserve nanosecond precision in Python dataset construction#8406sophianggan wants to merge 1 commit into
sophianggan wants to merge 1 commit into
Conversation
sophianggan
marked this pull request as ready for review
August 6, 2026 02:43
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.
What it is
Preserves exact nanosecond precision for pandas timestamps and timedeltas when users declare
Value("timestamp[ns]")orValue("duration[ns]").Previously,
Dataset.from_dict,Dataset.from_list, andDataset.mapreported a nanosecond feature while silently storing values truncated to microseconds. For example,2024-01-01 00:00:00.123456789became2024-01-01 00:00:00.123456.How it works
During Python dataset construction, pandas temporal scalars were first converted to microsecond-resolution Python objects. The writer then created an untyped Arrow array, so the discarded digits could not be recovered by the later cast to
timestamp[ns]orduration[ns].pa.array(...), allowing PyArrow to preserve the requested resolution from the start.Scope
The new path applies only to explicitly declared nanosecond timestamp and duration features. Default Python-object conversion, other temporal units, and undeclared type inference remain unchanged.
The fix supports naive and timezone-aware timestamps, timedeltas, mixed pandas and Python values, nulls,
try_type, nested lists, and nested structs.Verification
int64values for timestamps, durations, timezone-aware values, mixed temporal inputs, nulls,try_type, and nested features.Dataset.from_dict,Dataset.from_list, andDataset.map, checking both decoded rows and underlying Arrow storage.Featuresdictionary mutations.1704067200123456789and duration86400123456789exactly.Checks
Closes #8391.