pydata / pydata/xarray

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

Open
#10,727 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs mcve
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

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

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

Start by running the minimal Python example using DataArray.to_zarr and xr.open_zarr, then inspect the object-coordinate serialization path indicated by the numcodecs.vlen.VLenUTF8 traceback. Done means an object-typed coordinate can be written to Zarr, reopened, and written to a second Zarr store without the TypeError.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.