Skip to content

Commit 9fd641d

Browse files
gautehCopilot
andcommitted
fix: encode time vars with float64 and clean epoch for xarray >= 2025 compat
xarray 2025.9.0 switched to a numpy-based time decoder that fails in two ways: - rejects reference times with non-zero seconds (e.g. 'seconds since 2022-11-12 00:00:37') - overflows when decoding NaT (int64.min) stored as integer seconds Fix by explicitly encoding time and time_waves_imu with 'seconds since 1970-01-01' and dtype=float64 so NaT round-trips as NaN. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 41e6be2 commit 9fd641d

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

tests/test_read_omb_csv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_read_csv_omb_default_waves(test_data, tmpdir):
2020

2121
ds.to_netcdf(tmpdir / 'test.nc')
2222

23-
ds2 = xr.open_dataset(tmpdir / 'test.nc')
23+
ds2 = xr.open_dataset(tmpdir / 'test.nc', decode_cf=True)
2424
assert ds2.attrs['time_coverage_start'] == '2022-11-12T00:00:37'
2525
assert ds2.attrs['time_coverage_end'] == '2022-11-12T02:30:27'
2626

trajan/readers/omb.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,4 +488,15 @@ def read_omb_csv(path_in: Path|pd.DataFrame,
488488
"created with trajan.reader.omb from a Rock7 Iridium CSV file of OMB transmissions"
489489
)
490490

491+
# Ensure time variables are encoded with a clean epoch and float dtype so
492+
# xarray's numpy-based decoder (xarray >= 2025) can round-trip through
493+
# netCDF. Using float64 avoids int64 overflow when NaT fill values are
494+
# decoded as large integer offsets.
495+
for tvar in ("time", "time_waves_imu"):
496+
if tvar in xr_result:
497+
xr_result[tvar].encoding.update({
498+
"units": "seconds since 1970-01-01",
499+
"dtype": "float64",
500+
})
501+
491502
return xr_result

0 commit comments

Comments
 (0)