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
Report
Description
MuData.write()andMuData.write_zarr()crash when any modality containslayers[None]in its AnnData. In anndata >= 0.13,AnnData(X=...)automaticallystores X as
layers[None], so this affects any newly created AnnData that has notbeen explicitly cleared.
Minimal Reproduction
Error
Traceback points to anndata's
write_elemreceivingk=Nonefrom mudata's_write_h5muat the line:dict(adata.layers)includes{None: X_matrix}, andwrite_elemcallsNone.startswith("/").Environment
Notes
layers[None]is not present).write_h5muandwrite_zarrpaths (both go through the sameanndata
write_elem).mdata.write()is called internally by mudata, so this breaks all writeoperations when modalities are created from scratch.
layers[None]before writing is not reliablebecause it may remove X depending on anndata version behavior.
Versions