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

Test modality passed as string #602

Merged
Merged
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
48 changes: 48 additions & 0 deletions tests/core/test_anndata.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,27 @@ def test_make_dense(self, adata: AnnData, inplace: bool, n_modalities: int):
]
)

@given(
adata=get_adata(max_obs=5, max_vars=5, sparse_entries=True),
inplace=st.booleans(),
)
def test_modalities_passed_as_string(self, adata: AnnData, inplace: bool):
modality_to_densify = self._subset_modalities(adata, n_modalities=1)[0]

returned_adata = make_dense(
adata=adata, modalities=modality_to_densify, inplace=inplace
)

if inplace:
assert returned_adata is None
assert not issparse(get_modality(adata=adata, modality=modality_to_densify))
else:
assert isinstance(returned_adata, AnnData)
assert not issparse(
get_modality(adata=returned_adata, modality=modality_to_densify)
)
assert issparse(get_modality(adata=adata, modality=modality_to_densify))


class TestMakeSparse(TestBase):
@given(
Expand Down Expand Up @@ -373,6 +394,33 @@ def test_make_sparse(self, adata: AnnData, inplace: bool, n_modalities: int):
]
)

@given(
adata=get_adata(max_obs=5, max_vars=5),
inplace=st.booleans(),
)
def test_modalities_passed_as_string(self, adata: AnnData, inplace: bool):
modality_to_make_sparse = self._subset_modalities(adata, n_modalities=1)[0]

returned_adata = make_sparse(
adata=adata, modalities=modality_to_make_sparse, inplace=inplace
)

if inplace:
assert returned_adata is None
if modality_to_make_sparse != "X":
assert issparse(
get_modality(adata=adata, modality=modality_to_make_sparse)
)
else:
assert isinstance(returned_adata, AnnData)
if modality_to_make_sparse != "X":
assert issparse(
get_modality(adata=returned_adata, modality=modality_to_make_sparse)
)
assert not issparse(
get_modality(adata=adata, modality=modality_to_make_sparse)
)


class TestObsDf(TestBase):
@given(data=st.data(), adata=get_adata())
Expand Down