expected errors for estimating probability_two_random_records_match
@@ -261,3 +261,46 @@ def test_prob_rr_match_link_and_dedupe_multitable():
)
prob = linker._settings_obj._probability_two_random_records_match
assert prob == 1
+
+
+def test_prob_rr_valid_range():
+
+ def check_range(p):
+ # boundaries are degenerate cases where we don't need a linkage model
+ # (if we believe those values to be accurate)
+ assert p < 1
+ assert p > 0
+
+ df = pd.DataFrame(
+ [
+ {"unique_id": 1, "first_name": "John", "surname": "Smith"},
+ {"unique_id": 2, "first_name": "John", "surname": "Williams"},
+ {"unique_id": 3, "first_name": "John", "surname": "Jones"},
+ {"unique_id": 4, "first_name": "John", "surname": "Davis"},
+ {"unique_id": 5, "first_name": "John", "surname": "Evans"},
+ ]
+ )
+
+ settings = {
+ "link_type": "dedupe_only",
+ "comparisons": [],
+ }
+
+ # Test dedupe only
+ linker = DuckDBLinker(df, settings)
+ with pytest.raises(ValueError):
+ # all comparisons matches using this rule, so we must have perfect recall
+ # using recall = 80% is inconsistent, so should get an error
+ linker.estimate_probability_two_random_records_match(
+ "l.first_name = r.first_name", recall=0.8
+ )
+ check_range(linker._settings_obj._probability_two_random_records_match)
+
+ # no comparisons matches using this rule, so we will estimate value as 0
+ # this gives a linkage model that always predicts match_probability as 0,
+ # so should give an error at this stage
+ with pytest.raises(ValueError):
+ linker.estimate_probability_two_random_records_match(
+ "l.surname = r.surname", recall=0.7
+ )
+ check_range(linker._settings_obj._probability_two_random_records_match)
