Skip to content

Commit 3a44d08

Browse files
authored
Merge pull request #113 from cytomining/fix/silent-thread-map-leave-kwarg
Fix silent_thread_map passing invalid 'leave' kwarg
2 parents 1be231a + 0cb0d8a commit 3a44d08

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/copairs/map/map.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,15 @@ def get_p_value(params):
108108

109109
if progress_bar:
110110
from tqdm.contrib.concurrent import thread_map
111-
else:
112-
thread_map = silent_thread_map
113111

114-
map_scores["p_value"] = thread_map(
115-
get_p_value, params.values, leave=False, max_workers=max_workers
116-
)
112+
p_values = thread_map(
113+
get_p_value, params.values, leave=False, max_workers=max_workers
114+
)
115+
else:
116+
p_values = silent_thread_map(
117+
get_p_value, params.values, max_workers=max_workers
118+
)
119+
map_scores["p_value"] = p_values
117120

118121
# Perform multiple testing correction on p-values
119122
reject, pvals_corrected, alphacSidak, alphacBonf = multipletests(

tests/test_normalization_integration.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,30 @@ def test_mean_average_precision_with_normalization():
151151
result["treatment"] == treatment, "mean_normalized_average_precision"
152152
].values[0]
153153
assert abs(actual_norm_map - expected_norm_map) < 0.001
154+
155+
156+
def test_mean_average_precision_no_progress_bar():
157+
"""Test that mean_average_precision works with progress_bar=False."""
158+
from copairs.map.map import mean_average_precision
159+
160+
ap_scores = pd.DataFrame(
161+
{
162+
"treatment": ["A", "A", "B", "B"],
163+
"average_precision": [0.8, 0.7, 0.6, 0.5],
164+
"normalized_average_precision": [0.6, 0.5, 0.4, 0.3],
165+
"n_pos_pairs": [10, 10, 8, 8],
166+
"n_total_pairs": [50, 50, 40, 40],
167+
}
168+
)
169+
170+
# This should not raise TypeError about 'leave' argument
171+
result = mean_average_precision(
172+
ap_scores=ap_scores,
173+
sameby=["treatment"],
174+
null_size=100,
175+
threshold=0.05,
176+
seed=42,
177+
progress_bar=False,
178+
)
179+
180+
assert len(result) == 2

0 commit comments

Comments
 (0)