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
I'm trying to store a list of annotations for each row in an anndata object and save that object to h5ad.
The following snippet shows what I'm trying to do:
importanndataasadimportnumpyasnpimportpandasaspdn_cells=100n_genes=50adata=ad.AnnData(
X=np.random.normal(size=(n_cells, n_genes)),
obs=pd.DataFrame(index=[f"cell_{i}"foriinrange(n_cells)]),
var=pd.DataFrame(index=[f"gene_{i}"foriinrange(n_genes)]),
)
# Generate 10 fake annotationsu_annotations= [f"a{i}"foriinrange(10)]
# Randomly sample between 0 and 5 annotations for each cellannotations= [
np.random.choice(
u_annotations,
size=np.random.randint(0, 5),
replace=False,
).tolist()
for_inrange(n_cells)
]
# Add the annotations to the obs dataframeadata.obs["annotation"] =annotationsSAVE_PATH="./TEMP.h5ad"# Save to h5adadata.write_h5ad(SAVE_PATH) #This is where the error gets thrown# Load from h5adadata=ad.read_h5ad(SAVE_PATH)
Unfortunately this results in a TypeError:
TypeError: Can't implicitly convert non-string objects to strings
Above error raised while writing key 'annotation' of <class 'h5py._hl.group.Group'> to /
The text was updated successfully, but these errors were encountered:
I'm going to close this as a duplicate of #609. Let me know if you think this is different from that, and should be reopened.
We will have experimental support for this kind of data in the next release (which will have a release candidate soon) in the form of awkward arrays. If you want to try this out now, you can check out: #647.
I'm trying to store a list of annotations for each row in an anndata object and save that object to h5ad.
The following snippet shows what I'm trying to do:
Unfortunately this results in a
TypeError
:The text was updated successfully, but these errors were encountered: