Skip to content

Commit a4d3a5f

Browse files
more work on unit tests
1 parent ae59388 commit a4d3a5f

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

diffxpy/stats/stats.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ def mann_whitney_u_test(
5656
"""
5757
axis = 1
5858
if np.any(np.ndim(x0) != np.ndim(x1)):
59-
raise ValueError('stats.wilcoxon(): number of dimensions is not allowed to differ between x0 and x1!')
59+
raise ValueError('number of dimensions is not allowed to differ between x0 and x1')
6060
# Reshape into 2D array if only one test is performed.
6161
if np.ndim(x0) == 1:
6262
x0 = x0.reshape([x0.shape[0], 1])
6363
x1 = x1.reshape([x1.shape[0], 1])
6464
if np.any(x0.shape[axis] != x1.shape[axis]):
65-
raise ValueError(
66-
'stats.wilcoxon(): the first axis (number of tests) is not allowed to differ between x0 and x1!')
65+
raise ValueError('the first axis (number of tests) is not allowed to differ between x0 and x1')
6766

6867
pvals = np.asarray([
6968
scipy.stats.mannwhitneyu(

diffxpy/unit_test/test_data_types.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,38 @@ class TestDataTypesSingle(unittest.TestCase):
1515
def _test_wald(self, data, sample_description, gene_names=None):
1616
test = de.test.wald(
1717
data=data,
18-
factor_loc_totest="condition",
19-
formula_loc="~ 1 + condition",
2018
sample_description=sample_description,
2119
gene_names=gene_names,
22-
quick_scale=True,
23-
training_strategy="DEFAULT",
24-
dtype="float64"
20+
factor_loc_totest="condition",
21+
formula_loc="~ 1 + condition"
2522
)
2623
_ = test.summary()
2724

2825
def _test_lrt(self, data, sample_description, gene_names=None):
2926
test = de.test.lrt(
3027
data=data,
31-
full_formula_loc="~ 1 + condition",
32-
reduced_formula_loc="~ 1",
3328
sample_description=sample_description,
3429
gene_names=gene_names,
35-
quick_scale=True,
36-
training_strategy="DEFAULT",
37-
dtype="float64"
30+
full_formula_loc="~ 1 + condition",
31+
reduced_formula_loc="~ 1"
3832
)
3933
_ = test.summary()
4034

4135
def _test_t_test(self, data, sample_description, gene_names=None):
4236
test = de.test.t_test(
4337
data=data,
44-
grouping="condition",
4538
sample_description=sample_description,
46-
gene_names=gene_names
39+
gene_names=gene_names,
40+
grouping="condition"
4741
)
4842
_ = test.summary()
4943

5044
def _test_rank(self, data, sample_description, gene_names=None):
5145
test = de.test.rank_test(
5246
data=data,
53-
grouping="condition",
5447
sample_description=sample_description,
55-
gene_names=gene_names
48+
gene_names=gene_names,
49+
grouping="condition"
5650
)
5751
_ = test.summary()
5852

diffxpy/unit_test/test_extreme_values.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import numpy as np
55
import pandas as pd
6-
import scipy.stats as stats
76

87
from batchglm.api.models.glm_nb import Simulator
98
import diffxpy.api as de
@@ -19,6 +18,8 @@ def test_t_test_zero_variance(self):
1918
logging.getLogger("batchglm").setLevel(logging.WARNING)
2019
logging.getLogger("diffxpy").setLevel(logging.WARNING)
2120

21+
np.random.seed(1)
22+
de.pkg_constants.DE_TREAT_ZEROVAR_TT_AS_SIG = True
2223
sim = Simulator(num_observations=1000, num_features=10)
2324
sim.generate_sample_description(num_batches=0, num_conditions=0)
2425
sim.generate()
@@ -30,14 +31,14 @@ def test_t_test_zero_variance(self):
3031
})
3132

3233
test = de.test.t_test(
33-
data=sim.X,
34-
grouping="condition",
34+
data=sim.input_data,
3535
sample_description=random_sample_description,
36+
grouping="condition",
3637
is_sig_zerovar=True
3738
)
3839

3940
assert np.isnan(test.pval[0]) and test.pval[1] == 1, \
40-
"rank test did not assign p-value of zero to groups with zero variance and same mean, %f, %f" % \
41+
"t test did not assign p-value of zero to groups with zero variance and same mean, %f, %f" % \
4142
(test.pval[0], test.pval[1])
4243
return True
4344

@@ -49,6 +50,8 @@ def test_rank_test_zero_variance(self):
4950
logging.getLogger("batchglm").setLevel(logging.WARNING)
5051
logging.getLogger("diffxpy").setLevel(logging.WARNING)
5152

53+
np.random.seed(1)
54+
de.pkg_constants.DE_TREAT_ZEROVAR_TT_AS_SIG = True
5255
sim = Simulator(num_observations=1000, num_features=10)
5356
sim.generate_sample_description(num_batches=0, num_conditions=0)
5457
sim.generate()
@@ -60,9 +63,9 @@ def test_rank_test_zero_variance(self):
6063
})
6164

6265
test = de.test.rank_test(
63-
data=sim.X,
64-
grouping="condition",
66+
data=sim.input_data,
6567
sample_description=random_sample_description,
68+
grouping="condition",
6669
is_sig_zerovar=True
6770
)
6871

0 commit comments

Comments
 (0)