@@ -267,29 +267,30 @@ def test_wilcoxon_symmetry():
267267 assert np .allclose (np .abs (stats_mono ), np .abs (stats_dend ))
268268
269269
270- @pytest .mark .parametrize ("reference" , [True , False ])
271- def test_wilcoxon_tie_correction (reference ) :
270+ @pytest .mark .parametrize ("reference" , [True , False ], ids = [ "ref" , "rest" ] )
271+ def test_wilcoxon_tie_correction (* , reference : bool ) -> None :
272272 pbmc = pbmc68k_reduced ()
273273
274274 groups = ["CD14+ Monocyte" , "Dendritic" ]
275275 groupby = "bulk_labels"
276276
277277 _ , groups_masks = select_groups (pbmc , groups , groupby )
278278
279- x = pbmc .raw .X [groups_masks [0 ]].toarray ()
280-
281- mask_rest = groups_masks [1 ] if reference else ~ groups_masks [0 ]
282- y = pbmc .raw .X [mask_rest ].toarray ()
283-
284- pvals = mannwhitneyu (x , y , use_continuity = False , alternative = "two-sided" ).pvalue
285- pvals [np .isnan (pvals )] = 1.0
286-
287279 if reference :
288280 ref = groups [1 ]
281+ mask_rest = groups_masks [1 ]
289282 else :
290283 ref = "rest"
284+ mask_rest = ~ groups_masks [0 ]
291285 groups = groups [:1 ]
292286
287+ assert isinstance (pbmc .raw .X , CSBase )
288+ x = pbmc .raw .X [groups_masks [0 ]].toarray ()
289+ y = pbmc .raw .X [mask_rest ].toarray ()
290+
291+ pvals = mannwhitneyu (x , y , use_continuity = False , alternative = "two-sided" ).pvalue
292+ pvals [np .isnan (pvals )] = 1.0
293+
293294 test_obj = _RankGenes (pbmc , groups , groupby , reference = ref )
294295 with (
295296 pytest .warns (RuntimeWarning , match = r"invalid value encountered" )
@@ -298,7 +299,7 @@ def test_wilcoxon_tie_correction(reference):
298299 ):
299300 test_obj .compute_statistics ("wilcoxon" , tie_correct = True )
300301
301- np .testing .assert_allclose (test_obj .stats [groups [0 ]]["pvals" ], pvals )
302+ np .testing .assert_allclose (test_obj .stats [groups [0 ]]["pvals" ], pvals , atol = 1e-6 )
302303
303304
304305def test_wilcoxon_huge_data (monkeypatch ):
0 commit comments