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

(fix): resolve cupy import error on cupy-cuda12x<0.13 #1754

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/release-notes/1754.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix `cupy<0.13` imports in non-gpu environments {user}`ilan-gold`
11 changes: 10 additions & 1 deletion src/anndata/compat/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,16 @@
return "mock dask.array.core.Array"


if find_spec("cupy") or TYPE_CHECKING:
# https://github.com/scverse/anndata/issues/1749
def is_cupy_importable() -> bool:
try:
import cupy # noqa: F401
except ImportError:
return False
return True

Check warning on line 149 in src/anndata/compat/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/anndata/compat/__init__.py#L149

Added line #L149 was not covered by tests


if is_cupy_importable() or TYPE_CHECKING:
from cupy import ndarray as CupyArray
from cupyx.scipy.sparse import csc_matrix as CupyCSCMatrix
from cupyx.scipy.sparse import csr_matrix as CupyCSRMatrix
Expand Down
Loading