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 really enjoying the efficiency and scalability of anndata. I have been using it to manage my large datasets. Excellent work!
But unfortunately i'm having bad luck in writing adata object to .h5ad-formatted hdf5 file.
adata.write(results_file)
It takes very long time and ends up with one of the errors below (I haven't managed to store adata object in file)
IndexError: too many indices for array
2)ValueError: name already used as a name or title
In adata object, I'm using different annotations including uns, obs, vars, obsm and it works smoothly without any errors. But each time i try to write it to file, the aforementioned errors are thrown out.
I will really appreciate your opinions. Thanks in advance!
sorry about the slow response. I'm using dense matrix and in-memory mode.
It seems that it has something to do with 'uns' annotation. If I feed an anndata object to the unstructured annotation, when i save it, the writing process will get stuck and report error in the end.
I'm attaching a test script here. Hope it will help.
I'm just following up on adata.write. 'uns' annotation doesn't seemingly work for rpy2 object either. I got the following warning when trying to write adata to .h5ad-formatted hdf5 file. Is a python object required in order to write anndata object to files?
UserWarning: Could not save field with key = "uns/X_r_obj" to hdf5 file.
is invalid. But unfortunately, this doesn't throw an error. The .uns attribute allows for simple data types, numpy arrays, sparse matrices and simple dictionaries.
Use the .raw attribute of AnnData for doing what you want to do
adata.raw = adata
Let me think about whether there is an easy way of testing the type upon assignment.
Yes, of course, in a custom class - but that involves subclassing OrderedDict. It might be that this is not such a trouble as for DataFrames (also for arrays it wasn't trivial, as we saw). But that's the thing to be investigated before wrapping .uns's __setitem__ as you prototyped, right?
Hi, sorry that i have to reopen the issue. I'm having some trouble again when writing anndata object to a file.
I'm using dense matrix and in-memory mode.
When I ran adata.write(results_file), i got the error ''RuntimeError: Unable to create link (message type not found)"
5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/_objects.pyx in h5py._objects.with_phil.wrapper()
h5py/h5o.pyx in h5py.h5o.link()
RuntimeError: Unable to create link (message type not found)`
But if I run adata.write_loom(results_file), it works well.
I'm sorry about the limited information. I was running a big dataset so it was a bit difficult to provide an easily reproducible script.
But I guess i finally figured it out. I stored a dictionary into anndata unstructured annotation .uns. One keyword contains a slash symbol '/' , which resulted in the error 'RuntimeError: Unable to create link (message type not found)'`
/opt/Python-3.7.0/lib/python3.7/site-packages/anndata/readwrite/write.py:301: UserWarning: Could not save field with key = "uns/cell_type_categories" to hdf5 file.
'to hdf5 file.'.format(key))
Interesting, how come you have non-unicode values? Do you need them? Unicode is already super rich. A previous version of anndata only supported ASCII, which was limiting in some cases...
We absolutely don't need them, no. It happened by chance because user copy/pasted a block from a web site into their input. I corrected this and we were fine.
$ ./demo_load_maggie.py
Variable names are not unique. To make them unique, call `.var_names_make_unique`.
/opt/Python-3.7.0/lib/python3.7/site-packages/anndata/readwrite/write.py:301: UserWarning: Could not save field with key = "uns/condition_categories" to hdf5 file.
'to hdf5 file.'.format(key))
Hi all, i have been using scanpy library for three months now, just discovered that adata.write will give
"ValueError: name already used as a name or title" error if adata.obs contains a column name 'index'.
Just sharing in case anyone else has this problem too.
Reacted by Miles Smith, Anna Arutyunyan, Djamel NEHAR-BELAID, Simone Webb, Charlotte Soneson, JuHey, Will Macnair and Kane Foster
I get a write error: Above error raised while writing key 0 of <class 'h5py._hl.group.Group'> from /.
if a name of the index to the var table is an int. Setting the name to a string fixes this.
I get a write error: Above error raised while writing key 0 of <class 'h5py._hl.group.Group'> from /.
if a name of the index to the var table is an int. Setting the name to a string fixes this.
I have the same problem. How did you solve it? Thanks in advance!
Activity
Koncopd commentedon Aug 22, 2018
Hi, @huidongchen.
Do you write with sparse adata.X or dense?
Do you work in backed or in-memory mode?
huidongchen commentedon Aug 27, 2018
Hi ,
sorry about the slow response. I'm using dense matrix and in-memory mode.
It seems that it has something to do with 'uns' annotation. If I feed an anndata object to the unstructured annotation, when i save it, the writing process will get stuck and report error in the end.
I'm attaching a test script here. Hope it will help.
Thanks again.
test.ipynb.zip
huidongchen commentedon Aug 28, 2018
Hi,
I'm just following up on adata.write. 'uns' annotation doesn't seemingly work for rpy2 object either. I got the following warning when trying to write adata to .h5ad-formatted hdf5 file. Is a python object required in order to write anndata object to files?
UserWarning: Could not save field with key = "uns/X_r_obj" to hdf5 file.
I will appreciate your help.
falexwolf commentedon Aug 28, 2018
Hi!
The line
is invalid. But unfortunately, this doesn't throw an error. The
.unsattribute allows for simple data types, numpy arrays, sparse matrices and simple dictionaries.Use the
.rawattribute ofAnnDatafor doing what you want to doLet me think about whether there is an easy way of testing the type upon assignment.
Alex
flying-sheep commentedon Aug 29, 2018
well, of course there is, right?
huidongchen commentedon Aug 29, 2018
Thanks a lot @Koncopd @falexwolf . It's very helpful. I'm closing the issue.
falexwolf commentedon Sep 3, 2018
Yes, of course, in a custom class - but that involves subclassing OrderedDict. It might be that this is not such a trouble as for DataFrames (also for arrays it wasn't trivial, as we saw). But that's the thing to be investigated before wrapping
.uns's__setitem__as you prototyped, right?huidongchen commentedon Sep 10, 2018
Hi, sorry that i have to reopen the issue. I'm having some trouble again when writing anndata object to a file.
I'm using dense matrix and in-memory mode.
When I ran
adata.write(results_file), i got the error ''RuntimeError: Unable to create link (message type not found)"But if I run
adata.write_loom(results_file), it works well.falexwolf commentedon Sep 12, 2018
I'm sorry but with this amount of information, I cannot say anything.
huidongchen commentedon Sep 13, 2018
Hi Alex,
I'm sorry about the limited information. I was running a big dataset so it was a bit difficult to provide an easily reproducible script.
But I guess i finally figured it out. I stored a dictionary into anndata unstructured annotation
.uns. One keyword contains a slash symbol'/', which resulted in the error'RuntimeError: Unable to create link (message type not found)'`'repr'+'eval'strategy helps solve this issue.falexwolf commentedon Sep 17, 2018
Ah, thank you for this information! Indeed, HDF5 has problems with slashes. I'll reopen this issue so that we can print out a warning in the future.
jorvis commentedon Jan 15, 2019
I ran into this too:
jorvis commentedon Jan 16, 2019
Mine actually happened because there were non-unicode values in the cells of the cell_type column. Just a note.
falexwolf commentedon Jan 21, 2019
Interesting, how come you have non-unicode values? Do you need them? Unicode is already super rich. A previous version of anndata only supported ASCII, which was limiting in some cases...
jorvis commentedon Jan 21, 2019
We absolutely don't need them, no. It happened by chance because user copy/pasted a block from a web site into their input. I corrected this and we were fine.
flying-sheep commentedon Jan 21, 2019
Can you please give a reproducible example? Python does unicode by default, there should be almost no effort to fix this.
The only reason we don’t have tests for this is that I wouldn’t think it’d ever be a problem.
jorvis commentedon Jan 21, 2019
Attaching a demo dataset with test conversion script.
issue_52_demo.tar.gz
For me, it errors like this:
tantk commentedon Aug 8, 2019
Hi all, i have been using scanpy library for three months now, just discovered that adata.write will give
"ValueError: name already used as a name or title" error if adata.obs contains a column name 'index'.
Just sharing in case anyone else has this problem too.
jeffhsu3 commentedon Feb 12, 2020
I get a write error:
Above error raised while writing key 0 of <class 'h5py._hl.group.Group'> from /.if a name of the index to the var table is an int. Setting the name to a string fixes this.
flying-sheep commentedon Feb 12, 2020
Yeah, this is not supported. We should improve the error in this case though
ivirshup commentedon Feb 13, 2020
I'm going to close this, since new writing problems should open up new issues.
zznx commentedon Oct 13, 2020
I have the same problem. How did you solve it? Thanks in advance!
yebinase commentedon Jan 21, 2021
Hi, for me it has something to do with duplicated column ( or duplication between column and index), you might want to remove that