Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Opt out of floor division for float dtype time encoding #9497

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

spencerkclark
Copy link
Member

This PR provides a quick fix for #9488.

Previously for datetime64[ns] and timedelta64[ns] values we would always use floor division to encode times if we knew that all non-"NaT" values could be represented with integers with the given units, even if we would ultimately cast the values to floats later based on the specified dtype. This causes a problem when encoding "NaT" values, because the placeholder integer value is converted to a float here, which prevents it from properly being filled with the fill value later in the encoding process.

This PR changes things such that if we know that we will convert to floats eventually, we will use floating point division from the start, which preserves "NaT" values as floating point np.nan values. I update and test the behavior for both datetime64[ns] values and timedelta64[ns] values.

cc: @kmuehlbauer

@kmuehlbauer
Copy link
Contributor

Awesome, really just right around the corner. Thanks so much @spencerkclark!

@dcherian dcherian merged commit ef42335 into pydata:main Sep 16, 2024
28 checks passed
@spencerkclark spencerkclark deleted the fix-9488 branch September 17, 2024 00:25
dcherian added a commit to dcherian/xarray that referenced this pull request Sep 17, 2024
* main:
  Opt out of floor division for float dtype time encoding (pydata#9497)
  fixed formatting for whats-new (pydata#9493)
dcherian added a commit to dcherian/xarray that referenced this pull request Sep 17, 2024
* main:
  Opt out of floor division for float dtype time encoding (pydata#9497)
  fixed formatting for whats-new (pydata#9493)
  Forbid modifying names of DataTree objects with parents (pydata#9494)
  DAS-2155 - Merge datatree documentation into main docs. (pydata#9033)
  Make illegal path-like variable names when constructing a DataTree from a Dataset (pydata#9378)
  Ensure TreeNode doesn't copy in-place (pydata#9482)
  `open_groups` for zarr backends (pydata#9469)
  Update pyproject.toml (pydata#9484)
  New whatsnew section (pydata#9483)
hollymandel pushed a commit to hollymandel/xarray that referenced this pull request Sep 23, 2024
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.

writing datetime64 in netCDF may produce badly formatted or unreadable files
3 participants