You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Merging AnnData.obs object with Pandas DataFrame may fail #441
Given an AnnData object adata, it is currently not possible to merge adata.obs with a Pandas DataFrame if the resulting index differs from the original adata.obs_names.
Traceback (most recent call last):
File "<stdin>", line 1, in<module>
File "/opt/anaconda3/envs/anndata_bug/lib/python3.8/site-packages/anndata/_core/anndata.py", line 834, in obs
self._set_dim_df(value, "obs")
File "/opt/anaconda3/envs/anndata_bug/lib/python3.8/site-packages/anndata/_core/anndata.py", line 783, in _set_dim_df
value_idx = self._prep_dim_index(value.index, attr)
File "/opt/anaconda3/envs/anndata_bug/lib/python3.8/site-packages/anndata/_core/anndata.py", line 795, in _prep_dim_index
raise ValueError(
ValueError: Length of passed value for obs_names is 2, but this AnnData has shape: (3, 3)
Is this intended or is it planned to allow merges of this kind in the future? Is there an easier workaround than subsetting both the DataFrame and AnnData prior to merging?
Activity
ivirshup commentedon Nov 9, 2020
I don't think we'll allow assignment to the
.obsattribute to change the shape of theAnnDataobject, no.ivirshup commentedon Nov 9, 2020
I think it could be useful for this kind of thing to be easier. Not sure what the right api is for it though.
WeilerP commentedon Nov 19, 2020
How about a new class method
merge_obswhich basically executes the following steps:The arguments to tweak Pandas
alignandmergeshould be arguments of the method.ivirshup commentedon Nov 20, 2020
How about something more like
xarray.merge? This could reuse code/ arguments fromanndata.concat. Usage could look like:One issue is that this doesn't mutate the
AnnDataobject, but there could be an inplace variant that just didn't allow outer joins.This could also lead to adding
reindexandreindex_likemethods.ivirshup commentedon Dec 6, 2021
I'm going to close this in favor of #658 where I've fleshed the idea out a bit more, so what would actually be implemented is the focus of the issue