Skip to content

Commit 24be344

Browse files
author
brandon
committed
Add tolerance to detector confidence values for get_or_create_detector
1 parent 7b42626 commit 24be344

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/groundlight/client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=too-many-lines
22
import logging
3+
import math
34
import os
45
import time
56
import warnings
@@ -55,6 +56,10 @@
5556
# The system defaults can be stupidly long
5657
# It used to take >8 min to timeout to a bad IP address
5758
DEFAULT_REQUEST_TIMEOUT = 10 # seconds
59+
# There may be numerical noise if the confidence is ever saved in two different systems.
60+
# The confidence threshold is not that precise anyways, so we apply a tollerance within which
61+
# confidences are considered the same.
62+
DETECTOR_CONFIDENCE_TOLERANCE = 0.0001
5863

5964

6065
class GroundlightClientError(Exception):
@@ -555,7 +560,9 @@ def get_or_create_detector( # noqa: PLR0913
555560
f"Found existing detector with name={name} (id={existing_detector.id}) but the group names don't"
556561
f" match. The existing group name is '{existing_detector.group_name}'.",
557562
)
558-
if confidence_threshold is not None and existing_detector.confidence_threshold != confidence_threshold:
563+
if confidence_threshold is not None and not math.isclose(
564+
existing_detector.confidence_threshold, confidence_threshold, abs_tol=DETECTOR_CONFIDENCE_TOLERANCE
565+
):
559566
raise ValueError(
560567
f"Found existing detector with name={name} (id={existing_detector.id}) but the confidence"
561568
" thresholds don't match. The existing confidence threshold is"

0 commit comments

Comments
 (0)