Skip to content

Commit

Permalink
[python] Allow adata.X to be None (#1767)
Browse files Browse the repository at this point in the history
* [python] Ingest `adata.X==None`

* [python] Ingest `adata.X==None`

* neaten

* code-review feedback
  • Loading branch information
johnkerl authored and github-actions[bot] committed Oct 9, 2023
1 parent aa3407e commit 64650e8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
6 changes: 3 additions & 3 deletions apis/python/src/tiledbsoma/io/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,10 +510,10 @@ def from_anndata(
# chunkwise into memory.
# Using the latter allows us to ingest larger .h5ad files without OOMing.

# Some AnnData objects have no X at all.
has_X = True
# Some AnnData objects have no X at all. This might be a missing attribute
# anndata.X; it might be anndata.X present, but with value None.
try:
anndata.X
has_X = anndata.X is not None
except (NameError, KeyError):
# We need to check both -- different exception types occur dependinng
# on whether the anndata object is read in backing mode or not.
Expand Down
File renamed without changes.
Binary file not shown.
9 changes: 7 additions & 2 deletions apis/python/tests/test_basic_anndata_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,18 @@ def h5ad_file_categorical_int_nan(request):

@pytest.fixture
def h5ad_file_X_empty(request):
input_path = HERE.parent / "testdata/xempty.h5ad"
"""adata.X is a zero-cell sparse matrix"""
input_path = HERE.parent / "testdata/x-empty.h5ad"
return input_path


@pytest.fixture
def h5ad_file_X_none(request):
input_path = HERE.parent / "testdata/xnone.h5ad"
"""
adata.X has Python value None if read in non-backed mode; if read in backed
mode, adata.X is not present as an attribute of adata.
"""
input_path = HERE.parent / "testdata/x-none.h5ad"
return input_path


Expand Down

0 comments on commit 64650e8

Please sign in to comment.