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

Forbidden types #14

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
41 changes: 18 additions & 23 deletions src/dummy_anndata/generate_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,31 @@ def generate_dataset(
check_iterable_types(uns_types, "uns_types")
check_iterable_types(nested_uns_types, "nested_uns_types")

obsm_vector_forbidden = set(
[
"categorical",
"categorical_ordered",
"categorical_missing_values",
"categorical_ordered_missing_values",
"nullable_integer_array",
"nullable_boolean_array",
]
)
varm_vector_forbidden = obsm_vector_forbidden

assert layer_types is None or all(t in matrix_generators.keys() for t in layer_types), "Unknown layer type"
assert obs_types is None or all(t in vector_generators.keys() for t in obs_types), "Unknown obs type"
assert var_types is None or all(t in vector_generators.keys() for t in var_types), "Unknown var type"
assert obsm_types is None or all(
t in matrix_generators.keys() or t in vector_generators.keys() or t[3:] in vector_generators and t[:3] == "df_" for t in obsm_types
), "Unknown obsm type"
assert obsm_types is None or all(t not in obsm_vector_forbidden for t in obsm_types), "Forbidden obsm type"

assert varm_types is None or all(
t in matrix_generators.keys() or t in vector_generators.keys() or t[3:] in vector_generators and t[:3] == "df_" for t in varm_types
), "Unknown varm type"
assert varm_types is None or all(t not in varm_vector_forbidden for t in varm_types), "Forbidden varm type"

assert obsp_types is None or all(t in matrix_generators.keys() for t in obsp_types), "Unknown obsp type"
assert varp_types is None or all(t in matrix_generators.keys() for t in varp_types), "Unknown varp type"
# TODO uns types
Expand All @@ -99,30 +115,9 @@ def generate_dataset(
if var_types is None: # var_types are all vectors
var_types = list(vector_generators.keys())
if obsm_types is None: # obsm_types are all matrices or vectors, except for categoricals and nullables
vector_not_allowed = set(
[
"categorical",
"categorical_ordered",
"categorical_missing_values",
"categorical_ordered_missing_values",
"nullable_integer_array",
"nullable_boolean_array",
]
)
obsm_types = list(set(matrix_generators.keys()) - vector_not_allowed) + [f"df_{t}" for t in vector_generators.keys()]
obsm_types = list(set(matrix_generators.keys()) - obsm_vector_forbidden) + [f"df_{t}" for t in vector_generators.keys()]
if varm_types is None: # varm_types are all matrices or vectors, except for categoricals and nullables
vector_not_allowed = set(
[
"categorical",
"categorical_ordered",
"categorical_missing_values",
"categorical_ordered_missing_values",
"nullable_integer_array",
"nullable_boolean_array",
]
)
varm_types = list(set(matrix_generators.keys()) - vector_not_allowed) + [f"df_{t}" for t in vector_generators.keys()]

varm_types = list(set(matrix_generators.keys()) - varm_vector_forbidden) + [f"df_{t}" for t in vector_generators.keys()]
if obsp_types is None: # obsp_types are all matrices
obsp_types = list(matrix_generators.keys())
if varp_types is None: # varp_types are all matrices
Expand Down
14 changes: 13 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import dummy_anndata

import pytest

def test_package_has_version():
assert dummy_anndata.__version__ is not None
Expand Down Expand Up @@ -27,3 +27,15 @@ def test_uns():
def test_empty_x():
dummy = dummy_anndata.generate_dataset()
assert dummy.X is None


def test_forbidden_obsm_varm_types():
with pytest.raises(AssertionError) as ae:
dummy = dummy_anndata.generate_dataset(obsm_types=["categorical"])

assert ae.match("Forbidden obsm type")

with pytest.raises(AssertionError) as ae:
dummy = dummy_anndata.generate_dataset(varm_types=["categorical"])

assert ae.match("Forbidden varm type")
Loading