Skip to content

Conversation

@dcherian
Copy link
Contributor

@dcherian dcherian commented Jul 1, 2025

Closes #2847

Following the proposal in #8005 (comment), this PR adds encoding/decoding machinery for pd.IntervalArray objects. I use an ad-hoc convention:

  1. The data is stacked to a 2D array with the first dimension named __xarray_bounds__. This is not configurable at the moment.
  2. we record encoding attributes "closed", and "dtype" (this is always "pandas_interval").

It is possible to create an IntervalArray with Datetime and Timedelta objects so I've stuck the IntervalCoder first in the encoding pipeline, and last in the decoding pipeline. That way it stays independent.

TODO:

  • Add whats-new
  • Add decode_intervals kwarg?
  • Add docs to the "Internals" section.

coder = variables.IntervalCoder()
encoded = coder.encode(v)
expected = xr.Variable(
dims=("__xarray_bounds__", "time"),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could make this trailing dimension

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot store data after groupby_bins

1 participant