Skip to content

Expand types of Dataset keys that can be saved to disk #10221

Open
@ianhi

Description

@ianhi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementtopic-metadataRelating to the handling of metadata (i.e. attrs and encoding)topic-zarrRelated to zarr storage library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions