Skip to content

Commit d6cceeb

Browse files
committed
Neglect order of neighbors in knn test and add tolerance for max marker correlation test
1 parent 5f475a2 commit d6cceeb

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

tests/evaluation/test_metrics.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ def test_correlation_matrix_shared_comp_minimal():
127127
@pytest.mark.parametrize("ks", [[10, 20], [5, 9]])
128128
@pytest.mark.parametrize("genes", ["all", ["PPBP", "SPARC", "S100A8"], ["PPBP", "S100A9", "LYZ", "BLVRB"]])
129129
def test_knns_shared_comp(small_adata, ks, genes):
130-
"""
131-
#TODO: test for same set of neighbors per row instead of asserting that the order is also the same. (Lead to
132-
failures when there were some changes in the knn function.)
133-
"""
130+
""" """
134131
df = knns(small_adata, genes=genes, ks=ks)
135132
# to create the reference dataframe
136133
# df.to_csv(f"tests/evaluation/test_data/knn_df_{ks}_{genes}.csv")
137134
ref_df = pd.read_csv(f"tests/evaluation/test_data/knn_df_{ks}_{genes}.csv", index_col=0)
138-
assert df.equals(ref_df)
135+
# It's sufficient to check that the same values per row are present, order can differ based on platform and algorithm
136+
df_sorted = pd.DataFrame(np.sort(df.values, axis=1), index=df.index, columns=df.columns)
137+
ref_df_sorted = pd.DataFrame(np.sort(ref_df.values, axis=1), index=ref_df.index, columns=ref_df.columns)
138+
assert df_sorted.equals(ref_df_sorted)
139139

140140

141141
############################
@@ -246,7 +246,7 @@ def test_max_marker_correlations(small_adata, marker_list, small_probeset):
246246
# mmc.to_csv("tests/evaluation/test_data/max_marker_correlation.csv")
247247
mmc_ref = pd.read_csv("tests/evaluation/test_data/max_marker_correlation.csv", index_col=0)
248248
mmc_ref.columns.name = "index"
249-
assert pd.testing.assert_frame_equal(mmc, mmc_ref) is None
249+
pd.testing.assert_frame_equal(mmc, mmc_ref, check_exact=False, atol=1e-5)
250250

251251

252252
########################

0 commit comments

Comments
 (0)