Skip to content

Commit

Permalink
Fixes #2 and generates empty uns if asked for
Browse files Browse the repository at this point in the history
  • Loading branch information
LouiseDck committed Nov 7, 2024
1 parent ee148fe commit 36d020a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
27 changes: 11 additions & 16 deletions src/dummy_anndata/generate_dict.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from .generate_vector import vector_generators
from .generate_matrix import matrix_generators

import pandas as pd
import numpy as np

from .generate_matrix import matrix_generators
from .generate_vector import vector_generators

scalar_generators = {
"string": "version",
"char": "a",
Expand Down Expand Up @@ -34,17 +33,13 @@ def generate_type(type, n_rows, n_cols):

def generate_dict(n_rows, n_cols, types=None, nested=True):
if types is None: # types are all vectors and all matrices
scalar_types = list(scalar_generators.keys()) + [
f"scalar_{t}" for t in vector_generators.keys()
]
types = (
scalar_types
+ list(vector_generators.keys())
+ list(matrix_generators.keys())
)

data = {t: generate_type(t, n_rows, n_cols) for t in types}
if nested:
data["nested"] = generate_dict(n_rows, n_cols, types, False)
scalar_types = list(scalar_generators.keys()) + [f"scalar_{t}" for t in vector_generators.keys()]
types = scalar_types + list(vector_generators.keys()) + list(matrix_generators.keys())

data = {}
if types: # types is not empty
data = {t: generate_type(t, n_rows, n_cols) for t in types}
if nested:
data["nested"] = generate_dict(n_rows, n_cols, types, False)

return data
8 changes: 6 additions & 2 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pytest

import dummy_anndata


Expand All @@ -13,3 +11,9 @@ def test_generating_dataset(tmp_path):
dummy = dummy_anndata.generate_dataset()
filename = tmp_path / "dummy.h5ad"
dummy.write_h5ad(filename)


def test_empty_uns():
dummy = dummy_anndata.generate_dataset(uns_types=[])

assert dummy.uns == {}

0 comments on commit 36d020a

Please sign in to comment.