Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,4 @@ v<1.1.0>, <05/08/2026> -- Updated docs infrastructure based on pyproject
v<1.1.0>, <05/08/2026> -- Modernized repo infrastructure to use pyproject
v<1.1.0>, <05/08/2026> -- Moved tests and updated them to use pytest
v<1.1.0>, <05/08/2026> -- Modernized CI and publish pipelines
v<1.1.2>, <07/30/2026> -- Fixed spurious "threshold outside the range" warning emitted by the DUMMY thresholder on every default call
12 changes: 10 additions & 2 deletions pythresh/thresholds/dummy.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,17 @@ def eval(self, decision):

eps = np.finfo(decision.dtype).eps
perc = (1 - self.contam) * 100
limit = np.percentile(decision, perc) + eps

self._check_threshold(limit)
# ``decision`` is min-max normalized to [0, 1], so the percentile is
# also in [0, 1]. Adding eps keeps the top-scoring point an inlier at
# contam=0 (``cut`` uses ``decision >= limit``). Validate the in-range
# percentile rather than the eps-bumped limit; otherwise the maximum
# score (percentile == 1) makes limit == 1 + eps and trips a spurious
# "threshold outside the range" warning on every default call.
perc_val = np.percentile(decision, perc)
limit = perc_val + eps

self._check_threshold(perc_val)

self.thresh_ = limit

Expand Down
22 changes: 22 additions & 0 deletions tests/test_dummy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import warnings
from itertools import product

import joblib
Expand Down Expand Up @@ -141,3 +142,24 @@ def test_save_and_load(tmp_path, scores, score_case):
loaded = joblib.load(file)

assert_equal(thres.predict(s), loaded.predict(s))


# -----------------------
# Regression: no spurious out-of-range warning
# -----------------------


@pytest.mark.parametrize("contam,score_case", param_grid)
def test_no_spurious_threshold_warning(scores, contam, score_case):
# DUMMY's threshold is a percentile of min-max normalized scores plus eps.
# At the maximum (contam=0) the eps used to push the limit to 1 + eps and
# trip the "threshold outside the range" check on every call. It must not.
_, idx = score_case
s = scores[idx]

with warnings.catch_warnings(record=True) as record:
warnings.simplefilter("always")
DUMMY(contam=contam).eval(s)

offending = [w for w in record if "outside the range" in str(w.message)]
assert not offending, f"DUMMY emitted a spurious out-of-range warning: {[str(w.message) for w in offending]}"