pydata / pydata/xarray

Expand types of `Dataset` keys that can be saved to disk

Open
#10,221 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement topic-metadata topic-zarr
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Is your feature request related to a problem?

For a few applications I can think of (e.g. OME-Zarr, single cell data) I (and others) have commonly used integers as the key.

Currently doing this:

import xarray as xr

xr.Dataset({1: xr.DataArray([1, 2])}).to_zarr("test.nc")

Gives this error:

TypeError: Invalid name 1 for DataArray or Dataset key: must be either a string or None for serialization to netCDF or zarr files
Describe the solution you'd like

Xarray handles this behind the scenes for me, saving that key as a str and encoding in the zarr metadata that on open_dataset it should be restored to an int. This could be generalized to other types as well.

Describe alternatives you've considered

Making an accessor that handles that conversion, but I'd prefer it just work for as many cases as practicable.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the Dataset serialization paths used by to_zarr and open_dataset, beginning with the key validation that raises the shown TypeError. Define supported key types and verify round-trip restoration through zarr metadata, including the integer-key example; the issue names no specific files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.