Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transition to backed mode fails with .raw specified #1666

Open
2 of 3 tasks
colganwi opened this issue Sep 5, 2024 · 0 comments
Open
2 of 3 tasks

Transition to backed mode fails with .raw specified #1666

colganwi opened this issue Sep 5, 2024 · 0 comments

Comments

@colganwi
Copy link

colganwi commented Sep 5, 2024

Please make sure these conditions are met

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of anndata.
  • (optional) I have confirmed this bug exists on the master branch of anndata.

Report

Code:

import tempfile
from pathlib import Path
import anndata as ad
import numpy as np

with tempfile.TemporaryDirectory() as tmp_dir:
    adata_src = ad.AnnData(X = np.eye(10))
    adata_src.raw = adata_src
    adata_src.filename = Path(tmp_dir) / "test.h5ad" # change to backed mode
    adata_src.write()

Traceback:

/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_core/anndata.py:1863: in write_h5ad
    write_h5ad(
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/h5ad.py:100: in write_h5ad
    write_elem(f, "raw", adata.raw, dataset_kwargs=dataset_kwargs)
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/specs/registry.py:378: in write_elem
    Writer(_REGISTRY).write_elem(store, k, elem, dataset_kwargs=dataset_kwargs)
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/utils.py:247: in func_wrapper
    return func(*args, **kwargs)
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/specs/registry.py:328: in write_elem
    return write_func(store, k, elem, dataset_kwargs=dataset_kwargs)
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/specs/registry.py:71: in wrapper
    result = func(g, k, *args, **kwargs)
/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_io/specs/methods.py:322: in write_raw
    _writer.write_elem(g, "X", raw.X, dataset_kwargs=dataset_kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <anndata._core.raw.Raw object at 0x7f8cd6d9bdf0>

    @property
    def X(self) -> BaseCompressedSparseDataset | np.ndarray | sparse.spmatrix:
        # TODO: Handle unsorted array of integer indices for h5py.Datasets
        if not self._adata.isbacked:
            return self._X
        if not self._adata.file.is_open:
            self._adata.file.open()
        # Handle legacy file formats:
        if "raw/X" in self._adata.file:
            X = self._adata.file["raw/X"]
        elif "raw.X" in self._adata.file:
            X = self._adata.file["raw.X"]  # Backwards compat
        else:
>           raise AttributeError(
                f"Could not find dataset for raw X in file: "
                f"{self._adata.file.filename}."
            )
E           AttributeError: Could not find dataset for raw X in file: /tmp/tmpp9il7ydj/test.h5ad.
E           Error raised while writing key 'raw' of <class 'h5py._hl.group.Group'> to /

/home/wcolgan/miniconda3/envs/td-env/lib/python3.10/site-packages/anndata/_core/raw.py:81: AttributeError

Versions

Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import anndata, session_info; session_info.show(html=False, dependencies=True)
-----
anndata             0.10.9
session_info        1.0.0
-----
asciitree           NA
cython_runtime      NA
dateutil            2.8.2
exceptiongroup      1.2.0
h5py                3.10.0
natsort             8.4.0
numcodecs           0.12.1
numpy               1.26.4
packaging           23.1
pandas              2.2.0
pyarrow             15.0.0
pytz                2024.1
scipy               1.12.0
six                 1.16.0
sphinxcontrib       NA
zarr                2.17.1
zoneinfo            NA
-----
Python 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0]
Linux-5.4.0-137-generic-x86_64-with-glibc2.31
-----
Session information updated at 2024-09-04 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants