Skip to content

Commit ab2a7c2

Browse files
committed
make sure only valid keys are used in the threshold
1 parent 260d67d commit ab2a7c2

3 files changed

Lines changed: 18 additions & 1 deletion

File tree

src/spikeinterface/curation/tests/test_threshold_metrics_curation.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,3 +219,12 @@ def test_threshold_metrics_label_units_missing_metric_raises():
219219
thresholds = {"does_not_exist": {"greater": 0.0}}
220220
with pytest.raises(ValueError, match="specified in thresholds are not present"):
221221
threshold_metrics_label_units(metrics, thresholds)
222+
223+
224+
def test_threshold_metrics_label_units_invalid_threshold_keys_raises():
225+
import pandas as pd
226+
227+
metrics = pd.DataFrame({"m1": [1.0]}, index=[0])
228+
thresholds = {"m1": {"greater": 0.0, "invalid_key": 1.0}}
229+
with pytest.raises(ValueError, match="contains invalid keys"):
230+
threshold_metrics_label_units(metrics, thresholds)

src/spikeinterface/curation/threshold_metrics_curation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ def threshold_metrics_label_units(
7575
f"Available metrics are: {metrics.columns.tolist()}"
7676
)
7777

78+
# Check that threshold dictionaries contain only valid keys
79+
valid_keys = {"greater", "less", "abs"}
80+
for metric_name, threshold in thresholds_dict.items():
81+
if not set(threshold).issubset(valid_keys):
82+
raise ValueError(
83+
f"Threshold for metric '{metric_name}' contains invalid keys {set(threshold) - valid_keys}."
84+
)
85+
7886
if operator not in ("and", "or"):
7987
raise ValueError("operator must be 'and' or 'or'")
8088

src/spikeinterface/widgets/bombcell_curation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BombcellUpsetPlotWidget(BaseWidget):
3030
"non_soma", "non_soma_good", "non_soma_mua".
3131
thresholds : dict, optional
3232
Threshold dictionary with structure "noise", "mua", "non-somatic" as sections. Each section contains
33-
metric names keys with "greater" and "less" thresholds.
33+
metric names keys with "greater" and "less" thresholds.
3434
If None, uses default thresholds.
3535
unit_labels_to_plot : list of str, optional
3636
List of unit labels to include in the plot. If None, defaults to all labels in thresholds.

0 commit comments

Comments
 (0)