3
3
4
4
import matplotlib
5
5
import pytest
6
+ from polars .testing import assert_frame_equal
6
7
7
8
from rnalysis import filtering
8
9
from rnalysis .utils import enrichment_runner
@@ -17,7 +18,7 @@ def _df_to_dict(df, null_mode: bool = True):
17
18
if null_mode :
18
19
return {attr : set (df .filter (pl .col (attr ).is_not_null ()).select (pl .first ()).to_series ()) for attr in
19
20
df .columns [1 :]}
20
- return {attr : set (df .filter (pl .col (attr ) is True ).select (pl .first ()).to_series ()) for attr in df .columns [1 :]}
21
+ return {attr : set (df .filter (pl .col (attr )).select (pl .first ()).to_series ()) for attr in df .columns [1 :]}
21
22
22
23
23
24
def test_enrichment_runner_from_results ():
@@ -182,7 +183,7 @@ def test_results_to_csv():
182
183
def _compare_go_result_dfs (res , truth ):
183
184
res = res .sort (pl .first ())
184
185
truth = truth .sort (pl .first ())
185
- assert res .select (pl .col ('GO ID' , 'n' , 'obs' )). equals ( truth .select (pl .col ('GO ID' , 'n' , 'obs' )))
186
+ assert_frame_equal ( res .select (pl .col ('GO ID' , 'n' , 'obs' )), truth .select (pl .col ('GO ID' , 'n' , 'obs' )))
186
187
assert np .allclose (res .select (pl .col ('exp' , 'log2fc' , 'pval' )), res .select (pl .col ('exp' , 'log2fc' , 'pval' )), atol = 0 )
187
188
188
189
@@ -207,7 +208,6 @@ def __getitem__(self, item):
207
208
e .annotations = annotations
208
209
e .mutable_annotations = annotations ,
209
210
e .attributes = list (annotations .keys ())
210
-
211
211
res = pl .DataFrame ([i for i in e ._go_classic_on_batch (tuple (annotations .keys ()), 0 ).values ()],
212
212
schema = ['GO ID' , 'n' , 'obs' , 'exp' , 'log2fc' , 'pval' ])
213
213
_compare_go_result_dfs (res , truth )
@@ -354,7 +354,6 @@ def alt_calc_pval(self, log2fc: float, reps: int, obs_frac: float, bg_size: int,
354
354
355
355
attr = truth [0 ]
356
356
res = stats_test .run (attr , annotations [attr ], gene_set , background_set )
357
- print (res )
358
357
assert res == truth
359
358
360
359
@@ -732,8 +731,6 @@ def test_noncategorical_enrichment_runner_format_results(monkeypatch):
732
731
truth = io .load_table ('tests/test_files/non_categorical_enrichment_runner_format_results_truth.csv' )
733
732
runner .return_nonsignificant = True
734
733
runner .format_results (results_list )
735
- print (truth )
736
- print (runner .results )
737
734
assert truth .equals (runner .results )
738
735
739
736
@@ -1040,9 +1037,8 @@ def add_sig(self):
1040
1037
runner .en_score_col = 'colName'
1041
1038
runner .single_set = False
1042
1039
runner .return_nonsignificant = return_nonsignificant
1043
-
1044
1040
runner .format_results (results_dict )
1045
- assert truth . equals ( runner .results )
1041
+ assert_frame_equal ( truth , runner .results )
1046
1042
1047
1043
1048
1044
@pytest .mark .parametrize ("propagate_annotations,truth" ,
@@ -1200,7 +1196,6 @@ def _get_annotation_iter_zero(self):
1200
1196
runner .organism = "organism"
1201
1197
runner .taxon_id = "taxon id"
1202
1198
runner ._process_annotations ()
1203
- print (e )
1204
1199
1205
1200
1206
1201
def test_go_enrichment_runner_process_annotations (monkeypatch ):
0 commit comments