Skip to content

Allow passing coordinates in to_zarr(region=...) rather than passing indexes #7702

Description

@slevang

Is your feature request related to a problem?

If I want to write to a region of data in a zarr, I usually have some boilerplate code like this:

ds_existing = xr.open_zarr(path)
ds_new = xr.Dataset(...) # come up with some new data for a subset region of the existing zarr
start_idx = (ds_existing.time == ds_new.time[0]).argmax()
end_idx = (ds_existing.time == ds_new.time[-1]).argmax()
ds_new.to_zarr(path, region={"time": slice(start_idx, end_idx})

Describe the solution you'd like

It would be nice to automate this within to_zarr, because having to drop into index-space always feels un-xarray-like to me.

There may be pitfalls I'm not thinking of, and I don't know exactly what the API would look like.

ds_new.to_zarr(path, region={"time": "auto"}) # ???

Describe alternatives you've considered

No response

Additional context

No response

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions