Skip to content

Coordinate arrays of type object can not be written, read, and then written again with zarr<3 #10727

@joshua-gould

Description

@joshua-gould

What happened?

Coordinate arrays of type object can not be written, read, and then written again.

Minimal Complete Verifiable Example

import xarray as xr
import numpy as np

data = xr.DataArray(data=np.zeros((2, 2)),
                    dims=['x', 'y'],
                    coords=dict(
                        y=np.array(['a', 'b'],
                                   dtype=object)))
data.to_zarr("test.zarr", mode="w")
data = xr.open_zarr("test.zarr")
data.to_zarr("test2.zarr", mode="w")
# File "numcodecs/vlen.pyx", line 104, in numcodecs.vlen.VLenUTF8.encode
# TypeError: expected unicode string, found 2

MVCE confirmation

  • Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
  • Complete example — the example is self-contained, including all data and the text of any traceback.
  • Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
  • New issue — a search of GitHub Issues suggests this is not a duplicate.
  • Recent environment — the issue occurs with the latest version of xarray and its dependencies.

Environment

xarray==2025.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs mcvehttps://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions