Skip to content

mdata.write() / mdata.write_zarr() crashes with layers[None] on anndata >= 0.13 #183

Description

@Xparx

Report

Description

MuData.write() and MuData.write_zarr() crash when any modality contains
layers[None] in its AnnData. In anndata >= 0.13, AnnData(X=...) automatically
stores X as layers[None], so this affects any newly created AnnData that has not
been explicitly cleared.

Minimal Reproduction

import mudata as md
import anndata as ad
import numpy as np
import pandas as pd

obs = pd.DataFrame({'batch': ['B1'] * 10}, index=[f"cell_{i}" for i in range(10)])
x = np.random.randint(0, 10, (10, 10)).astype('float32')

adata = ad.AnnData(X=x, obs=obs)
print("anndata version:", ad.__version__)
print("layers[None] present:", None in adata.layers)

mdata = md.MuData({'rna': adata})
mdata.write("/tmp/test.h5mu")  # Also fails with write_zarr

Error

AttributeError: 'NoneType' object has no attribute 'startswith'

Traceback points to anndata's write_elem receiving k=None from mudata's
_write_h5mu at the line:

write_elem(group, "layers", dict(adata.layers), dataset_kwargs=kwargs)

dict(adata.layers) includes {None: X_matrix}, and write_elem calls
None.startswith("/").

Environment

  • anndata: 0.13.2
  • mudata: 0.3.8
  • zarr: 3.3.0

Notes

  • Does not occur with anndata 0.12.10 (where layers[None] is not present).
  • Affects both write_h5mu and write_zarr paths (both go through the same
    anndata write_elem).
  • mdata.write() is called internally by mudata, so this breaks all write
    operations when modalities are created from scratch.
  • A workaround of deleting layers[None] before writing is not reliable
    because it may remove X depending on anndata version behavior.

Versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions