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

[python] Add type checks to obsm, obsp, varm and varp early in ingestion #2131

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Changes from 2 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
25 changes: 25 additions & 0 deletions apis/python/src/tiledbsoma/io/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
from anndata._core import file_backing
from anndata._core.sparse_dataset import SparseDataset
from somacore.options import PlatformConfig
from typing_extensions import get_args

from .. import (
Collection,
Expand Down Expand Up @@ -421,6 +422,30 @@
"Second argument is not an AnnData object -- did you want from_h5ad?"
)

for key in anndata.obsm.keys():
if not isinstance(anndata.obsm[key], get_args(Matrix)):
raise TypeError(

Check warning on line 427 in apis/python/src/tiledbsoma/io/ingest.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/io/ingest.py#L427

Added line #L427 was not covered by tests
f"Obsm value at {key} in not of type {list(cl.__name__ for cl in get_args(Matrix))}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users will expect obsm not Obsm -- same for the other three

)

for key in anndata.obsp.keys():
if not isinstance(anndata.obsp[key], get_args(Matrix)):
raise TypeError(

Check warning on line 433 in apis/python/src/tiledbsoma/io/ingest.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/io/ingest.py#L433

Added line #L433 was not covered by tests
f"Obsp value at {key} in not of type {list(cl.__name__ for cl in get_args(Matrix))}"
)

for key in anndata.varm.keys():
if not isinstance(anndata.varm[key], get_args(Matrix)):
raise TypeError(

Check warning on line 439 in apis/python/src/tiledbsoma/io/ingest.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/io/ingest.py#L439

Added line #L439 was not covered by tests
f"Varm value at {key} in not of type {list(cl.__name__ for cl in get_args(Matrix))}"
)

for key in anndata.varp.keys():
if not isinstance(anndata.varp[key], get_args(Matrix)):
raise TypeError(

Check warning on line 445 in apis/python/src/tiledbsoma/io/ingest.py

View check run for this annotation

Codecov / codecov/patch

apis/python/src/tiledbsoma/io/ingest.py#L444-L445

Added lines #L444 - L445 were not covered by tests
f"Varp value at {key} in not of type {list(cl.__name__ for cl in get_args(Matrix))}"
)

# For single ingest (no append):
#
# * obs, var, X, etc array indices map 1-1 to soma_joinid, soma_dim_0, soma_dim_1, etc.
Expand Down
Loading