scanpy
scanpy copied to clipboard
Above error raised while reading key '/layers' of type <class 'h5py._hl.group.Group'>
I'm using scanpy 1.8.2, anndata 0.8.0 and h5py 3.1.0
I got this error while reading an h5ad file:
adata=sc.read_h5ad('XXXX.h5ad')
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
/opt/conda/lib/python3.8/site-packages/anndata/_io/utils.py in func_wrapper(elem, *args, **kwargs)
155 if zarr and isinstance(elem, (zarr.Group, zarr.Array)):
--> 156 parent = elem.store # Not sure how to always get a name out of this
157 elif isinstance(elem, SparseDataset):
/opt/conda/lib/python3.8/site-packages/anndata/_io/h5ad.py in read_group(group)
/opt/conda/lib/python3.8/enum.py in __getitem__(cls, name)
386 def __getitem__(cls, name):
--> 387 return cls._member_map_[name]
388
KeyError: 'dict'
During handling of the above exception, another exception occurred:
AnnDataReadError Traceback (most recent call last)
<ipython-input-15-a2632df74a34> in <module>
----> 1 adata=sc.read_h5ad('XXXX.h5ad')
/opt/conda/lib/python3.8/site-packages/anndata/_io/h5ad.py in read_h5ad(filename, backed, as_sparse, as_sparse_fmt, chunk_size)
/opt/conda/lib/python3.8/functools.py in wrapper(*args, **kw)
873 '1 positional argument')
874
--> 875 return dispatch(args[0].__class__)(*args, **kw)
876
877 funcname = getattr(func, '__name__', 'singledispatch function')
/opt/conda/lib/python3.8/site-packages/anndata/_io/utils.py in func_wrapper(elem, *args, **kwargs)
160 parent = elem.file.name
161 return parent
--> 162
163
164 def report_read_key_on_error(func):
AnnDataReadError: Above error raised while reading key '/layers' of type <class 'h5py._hl.group.Group'> from /.
Any ideas?
updating h5py to 3.6.0 seemed to have worked. Does it sound like right?
Encountering the same error. Updating h5py did not seem to help. Any advice on this?
I was having the same problem. conda update anndata solved my problem.
Encountering the same error. Updating h5py did not seem to help. Any advice on this?
This might be useful to you: https://github.com/scverse/scanpy/issues/1351#issuecomment-1198015945
@brianpenghe Hi may I consult how you resolved the problem?
The comment says upgrade anndata to 0.8.0 but mine already is 0.8.0 and the error message remains.
@Jiayi-Zheng Same for me.
Have you rebooted the python after updating anndata? Can you paste the exact error you're seeing? Are you allowed to share the object you're having trouble loading?
OP's error is bizarre, e.g. the last part seems to be pointing to an empty line. Like the package was updated but the python was not restarted. I can't recreate the exact one he's seeing, but I've managed to get other disjoint errors along those lines by updating anndata to 0.8.0 in a second terminal while the python in question is still running.
@ktpolanski I re-created a new conda env and installed scanpy so now it's working. I'm still not sure where the problem lies, though I did realize it starts jumping error after I install another package called stereopy, I'm guessing maybe that package updated something which got in conflict with normal scanpy setting.
@ktpolanski I thought I had the newest anndata version, but turns out 0.8.0 is not in Ubuntu repositiories. I had to manually download and install Python 3.8, anndata 0.8.0 and h5py, now it works.
@ktpolanski I re-created a new conda env and installed scanpy so now it's working. I'm still not sure where the problem lies, though I did realize it starts jumping error after I install another package called stereopy, I'm guessing maybe that package updated something which got in conflict with normal scanpy setting.
https://github.com/BGIResearch/stereopy/blob/6345d2732772a58d60351e790058bd5da1301fb5/requirements.txt#L26
updaing anndata from 0.7.6 to anndata 0.8 solved it for me
Seems like this is still an issue. I am getting this error below randomly. It disappears after trying sometime later with the exact code and files...
scanpy==1.9.4 anndata==0.9.2 umap==0.5.3 numpy==1.23.4 scipy==1.11.2 pandas==2.1.4 scikit-learn==1.3.0 statsmodels==0.14.0 igraph==0.10.6 louvain==0.8.1 pynndescent==0.5.10
adata=sc.read_h5ad('foo.h5ad')
Error:
AnnDataReadError: Above error raised while reading key '/X' of type <class 'h5py._hl.group.Group'> from /.
I'm not sure what is the cause of the problem and how to resolve it. But it I remove everything in the metadata aside from index and genecount/genenumber the error does not come up. So one solution is to save metadata to a csv and save the adata without too much metadata info.
anndata==0.9.2
Anndata is currently at 0.10.4. Please use the newest version if you want to check if a bug still exists.