Skip to content

Commit 5f3be07

Browse files
committed
Move tests to test_x
1 parent b9f6aca commit 5f3be07

File tree

2 files changed

+49
-26
lines changed

2 files changed

+49
-26
lines changed

anndata/tests/test_base.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -571,28 +571,3 @@ def assert_eq_not_id(a, b):
571571
assert_eq_not_id(map_sprs.keys(), map_copy.keys())
572572
for key in map_sprs.keys():
573573
assert_eq_not_id(map_sprs[key], map_copy[key])
574-
575-
576-
def test_x_is_none():
577-
# test setter and getter
578-
adata = AnnData(np.array([[1, 2, 3], [4, 5, 6]]), dict(o1=[1, 2], o2=[3, 4]))
579-
adata.X = None
580-
assert adata.X is None
581-
582-
# test setter and deleter
583-
adata.X = np.array([[4, 5, 6], [1, 2, 3]])
584-
assert adata.X is not None
585-
del adata.X
586-
assert adata.X is None
587-
588-
# test initialiser
589-
shape = (3, 5)
590-
adata = AnnData(None, uns=dict(test=np.array((3, 3))), shape=shape)
591-
assert adata.X is None
592-
assert adata.shape == shape
593-
594-
# test transpose
595-
adataT = adata.transpose()
596-
assert_equal(adataT.shape, (5, 3))
597-
assert_equal(adataT.obsp.keys(), adata.varp.keys())
598-
assert_equal(adataT.T, adata)

anndata/tests/test_x.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
import numpy as np
33
from scipy import sparse
44

5+
from anndata import AnnData
56
from anndata.utils import asarray
67

78
import pytest
89

9-
from anndata.tests.helpers import gen_adata
10+
from anndata.tests.helpers import gen_adata, assert_equal
1011

1112
UNLABELLED_ARRAY_TYPES = [
1213
pytest.param(sparse.csr_matrix, id="csr"),
@@ -22,6 +23,53 @@
2223
@pytest.mark.parametrize("orig_array_type", UNLABELLED_ARRAY_TYPES)
2324
@pytest.mark.parametrize("new_array_type", UNLABELLED_ARRAY_TYPES)
2425
def test_setter_singular_dim(shape, orig_array_type, new_array_type):
26+
# https://github.com/theislab/anndata/issues/500
2527
adata = gen_adata(shape, X_type=orig_array_type)
2628
adata.X = new_array_type(np.ones(shape))
2729
np.testing.assert_equal(asarray(adata.X), 1)
30+
31+
32+
###############################
33+
# Tests for `adata.X is None` #
34+
###############################
35+
36+
37+
def test_set_x_is_none():
38+
# test setter and getter
39+
adata = AnnData(np.array([[1, 2, 3], [4, 5, 6]]), dict(o1=[1, 2], o2=[3, 4]))
40+
adata.X = None
41+
assert adata.X is None
42+
43+
44+
def test_del_set_equiv_X():
45+
"""Tests that `del adata.X` is equivalent to `adata.X = None`"""
46+
# test setter and deleter
47+
orig = gen_adata((10, 10))
48+
copy = orig.copy()
49+
50+
del orig.X
51+
copy.X = None
52+
53+
assert orig.X is None
54+
assert_equal(orig, copy)
55+
56+
# Check that deleting again is still fine
57+
del orig.X
58+
assert orig.X is None
59+
60+
61+
def test_init_X_as_none():
62+
# test initialiser
63+
shape = (3, 5)
64+
adata = AnnData(None, uns=dict(test=np.array((3, 3))), shape=shape)
65+
assert adata.X is None
66+
assert adata.shape == shape
67+
68+
69+
@pytest.mark.parametrize("shape", SINGULAR_SHAPES + [pytest.param((5, 3), id="(5, 3)")])
70+
def test_transpose_with_X_as_none(shape):
71+
adata = gen_adata(shape, X_type=lambda x: None)
72+
adataT = adata.transpose()
73+
assert_equal(adataT.shape, shape[::-1])
74+
assert_equal(adataT.obsp.keys(), adata.varp.keys())
75+
assert_equal(adataT.T, adata)

0 commit comments

Comments
 (0)