Skip to content

Preserve nanosecond datetime precision with legacy microsecond defaults - #1273

Draft
alan-kumo wants to merge 1 commit into
NVIDIA:mainfrom
alan-kumo:bug-finesse-nanosecond-datetimes-20261027
Draft

alan-kumo wants to merge 1 commit into
NVIDIA:mainfrom
alan-kumo:bug-finesse-nanosecond-datetimes-20261027

Conversation

@alan-kumo

Copy link
Copy Markdown
Contributor

Summary

Preserve nanosecond datetime anchors without changing the legacy microsecond representation or supported date range.

Description of the change

Arrow/pandas timestamps with a nonzero nanosecond remainder currently fail at ingress:

import pyarrow as pa
from sdm import TableTensor

TableTensor.from_arrow(
    pa.table({"time": pa.array([1], type=pa.timestamp("ns"))}),
    {"time": "datetime"},
)
# pyarrow.lib.ArrowInvalid: Casting from timestamp[ns] to timestamp[us]
# would lose data: 1

Carry units per datetime column, retaining the existing microsecond path when conversion is lossless. Preserve units through table operations, serialization, ensemble packing, preprocessing, and model execution. Temporal sampling derives exact inclusive bounds for nanosecond queries against microsecond events; graphs with nanosecond events normalize clocks losslessly. Calendar and relative-day features interpret each column's units while keeping the legacy arithmetic unchanged.

New mixed-unit combinations that cannot fit the int64 nanosecond timestamp range raise a normal error. Cross-unit conversion is an eager validation boundary and synchronizes CUDA inputs; unchanged units retain their existing path. Mixed-unit in-place writes are rejected to preserve aliased views. Existing raw constructors and old serialized payloads continue to default to microseconds.

Validation

Manual CUDA checks on a local NVIDIA L4 cover temporal inclusion/equality around negative epochs, +1ns anchors, and the next microsecond; exact cuDF round trips; calendar-day rollover; and successful device use after rejecting an unsupported range. CPU checks cover the same boundaries, broad legacy dates, metadata propagation, old serialization, both column-selection modes, and eight-estimator forward plus cached fit/predict execution. A fullgraph eager-backend compiled same-unit view preserves nanosecond metadata.

Validation used Python 3.14.6, PyTorch 2.14.0+cu130, and PyArrow 23.0.1 (full CPU suite: 1,020 passed, 629 skipped; focused CPU/CUDA precision suite: 31 passed). A second read-only run with Python 3.11.15, PyTorch 2.12.1+cu130, and PyArrow 20.0.0 passed 160 focused tests with 36 optional skips: PyG, cuDF, cuGraph, and CuPy were unavailable in that environment. CUDA tensor/calendar/context-recovery tests ran there; sampling and cuDF were validated only in the first environment. All-files pre-commit passed. No benchmark results, dependency declarations, checkpoint changes, or runtime patches are included. Scored regressions remain blocked pending maintainer review of this fix.

@copy-pr-bot

copy-pr-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.26554% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.23%. Comparing base (1e2061b) to head (ed9b951).

Files with missing lines Patch % Lines
sdm/tensor/table.py 87.09% 12 Missing ⚠️
sdm/relational/backend/_cugraph.py 20.00% 4 Missing ⚠️
sdm/tensor/datetime.py 94.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1273      +/-   ##
==========================================
+ Coverage   82.99%   83.23%   +0.24%     
==========================================
  Files         176      178       +2     
  Lines       11385    11514     +129     
==========================================
+ Hits         9449     9584     +135     
+ Misses       1936     1930       -6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

This branch has not been deployed

No deployments
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.

1 participant