scverse / mudata

Multimodal Data (.h5mu) implementation for Python
https://mudata.rtfd.io
BSD 3-Clause "New" or "Revised" License
75 stars 17 forks source link

Modifying the `var`'s number of `mod` and then modifying the number of `obs` will trigger a `ValueError` #22

Closed liuzj039 closed 2 years ago

liuzj039 commented 2 years ago

Describe the bug

Mudata object can't be updated after slicing the mod's anndata and then slicing the mudata. To Reproduce

import scanpy as sc
import muon as mu
import pandas as pd

ad_1 = sc.AnnData(pd.DataFrame([list(range(5))] * 3))
ad_2 = sc.AnnData(pd.DataFrame([list(range(6))] * 5))

md = mu.MuData({'a':ad_1, 'b': ad_2})
print(md)
#MuData object with n_obs × n_vars = 5 × 11
#   2 modalities
#    a: 3 x 5
#    b: 5 x 6

md.mod['a'] = md.mod['a'][:, :2]
md.update()
md = md[:2]
md.update()
# ValueError:  Value passed for key 'a' is of incorrect shape. Values of varm must match dimensions (1,) of parent. Value had shape (2,) while it should have had (8,).
liuzj039 commented 2 years ago

It seems to be due to mudata not copied after slicing.

gtca commented 2 years ago

Hey, thanks for reporting. It seems to be just due to a typo that 82bd58b00995e5f752ccf40ff221f3bfb563653f should have fixed.