When trying to save my adata object:
adata_query_final.write_h5ad("anndata_objects/3_pcls_adata_with_scArches_labels_20240215.h5ad")
I received the following error:
TypeError: Can't implicitly convert non-string objects to strings
Error raised while writing key 'ann_level_2_transfer_uncert' of <class 'h5py._hl.group.Group'> to /
I have these columns in obs matrix which are supposed to float but some mix up there different type of variables for which I could not save the object.
'ann_level_1_transfer_uncert', 'ann_level_2_transfer_uncert', 'ann_level_3_transfer_uncert', 'ann_level_4_transfer_uncert', 'ann_level_5_transfer_uncert',
I checked the type of the variable in the columns using below command:
print(adata_query_final.obs['ann_level_1_transfer_uncert'].apply(type).value_counts())
ann_level_1_transfer_uncert <class 'numpy.float64'> 11075 <class 'int'> 1754 <class 'float'> 78 Name: count, dtype: int64Converted all the columns to float with command below:adata_query_final.obs['ann_level_1_transfer_uncert'] = adata_query_final.obs['ann_level_1_transfer_uncert'].astype(float) adata_query_final.obs['ann_level_2_transfer_uncert'] = adata_query_final.obs['ann_level_2_transfer_uncert'].astype(float) adata_query_final.obs['ann_level_3_transfer_uncert'] = adata_query_final.obs['ann_level_3_transfer_uncert'].astype(float) adata_query_final.obs['ann_level_4_transfer_uncert'] = adata_query_final.obs['ann_level_4_transfer_uncert'].astype(float) adata_query_final.obs['ann_level_5_transfer_uncert'] = adata_query_final.obs['ann_level_5_transfer_uncert'].astype(float)
Now, i can save the adata without an issue:
adata_query_final.write_h5ad("anndata_objects/3_pcls_adata_with_scArches_labels_20240215.h5ad")
No comments:
Post a Comment