Skip to content

Write second-resolution datetimes and timedeltas in the right unit - #995

Open
itzzdev09 wants to merge 1 commit into
dask:mainfrom
itzzdev09:fix/second-resolution-times
Open

itzzdev09 wants to merge 1 commit into
dask:mainfrom
itzzdev09:fix/second-resolution-times

Conversation

@itzzdev09

Copy link
Copy Markdown

Fixes #992.

Two unit errors in writer.convert for second-resolution columns:

  • datetime64[s] is written as TIMESTAMP_MILLIS, but its time_factors entry was used as a divisor, so seconds were divided by 1000 instead of multiplied. 2025-01-05 was stored as 1736035 ms, which the reader then cannot cast back to seconds.
  • timedelta64[s] fell through to the "already microseconds" branch and was stored as-is in the TIME_MICROS column, so 90061 s read back as 90061 µs (0 s at second resolution).

Both now scale up, keeping NaT as NaT the way the existing m8[ms] branch does.

The new test fails without the change (both has_nulls cases); the rest of the suite is unchanged (386 passed, pandas 3.1.1). I also round-tripped datetimes and timedeltas at s/ms/us/ns, naive and with UTC / Europe/Paris, with and without pandas_nulls, including NaT, a negative timedelta and the epoch: all match.

datetime64[s] values were divided by 1000 on their way to a
TIMESTAMP_MILLIS column instead of multiplied, and timedelta64[s] values
were stored as if already in microseconds. NaT is kept as NaT.

Fixes dask#992
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.

datetime64[s] and timedelta64[s] columns do not round-trip in 2026.9.0

1 participant