Skip to content

Conversation

copybara-service[bot]
Copy link

Manually set timedelta64 encoding to int32 before saving to netCDF.

This is required since xarray=2025.06.1 will not automatically cast int64 to int32 any more

This is required since xarray=2025.06.1 will not automatically cast int64 to int32 any more

PiperOrigin-RevId: 775606362
for coord in dataset.coords:
if dataset[coord].dtype == 'timedelta64[ns]':
# Make sure to also override all other existing encodings.
dataset[coord].encoding = {'dtype': 'int32'}
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend also adding:

if "_FillValue" in dataset[coord].encoding:
  # Let NetCDF pick a default that works for int32
  del dataset[coord].encoding["_FillValue"]

@copybara-service copybara-service bot closed this Jul 21, 2025
@copybara-service copybara-service bot deleted the test_775606362 branch July 21, 2025 19:40
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.

2 participants