add test for labels table
@@ -241,3 +241,71 @@ def test_roc_chart_link_and_dedupe():
linker._con.register("labels", df_labels)
linker.roc_chart_from_labels("labels")
+
+
+def test_prediction_errors_from_labels_table():
+
+ data = [
+ {"unique_id": 1, "first_name": "robin", "cluster": 1},
+ {"unique_id": 2, "first_name": "robin", "cluster": 1},
+ {"unique_id": 3, "first_name": "john", "cluster": 1},
+ {"unique_id": 4, "first_name": "david", "cluster": 2},
+ {"unique_id": 5, "first_name": "david", "cluster": 3},
+ ]
+ df = pd.DataFrame(data)
+
+ labels = [
+ (1, 2, 0.8),
+ (1, 3, 0.8),
+ (2, 3, 0.8),
+ (4, 5, 0.1),
+ ]
+
+ df_labels = pd.DataFrame(
+ labels, columns=["unique_id_l", "unique_id_r", "clerical_match_score"]
+ )
+ df_labels["source_dataset_l"] = "fake_data_1"
+ df_labels["source_dataset_r"] = "fake_data_1"
+
+ settings = {
+ "link_type": "dedupe_only",
+ "probability_two_random_records_match": 0.5,
+ "comparisons": [
+ {
+ "output_column_name": "first_name",
+ "comparison_levels": [
+ {
+ "sql_condition": '"first_name_l" IS NULL OR "first_name_r" IS NULL',
+ "label_for_charts": "Null",
+ "is_null_level": True,
+ },
+ {
+ "sql_condition": '"first_name_l" = "first_name_r"',
+ "label_for_charts": "Exact match",
+ "m_probability": 0.95,
+ "u_probability": 1e-5,
+ },
+ {
+ "sql_condition": "ELSE",
+ "label_for_charts": "All other comparisons",
+ "m_probability": 0.05,
+ "u_probability": 1 - 1e-5,
+ },
+ ],
+ }
+ ],
+ }
+
+ linker = DuckDBLinker(df, settings)
+
+ linker._initialise_df_concat_with_tf()
+ linker._con.register("labels", df_labels)
+
+ df = linker.prediction_errors_from_labels_table("labels").as_pandas_dataframe()
+ df = df[["unique_id_l", "unique_id_r"]]
+ records = list(df.to_records(index=False))
+ records = [tuple(p) for p in records]
+
+ assert (1, 3) in records
+ assert (2, 3) in records
+ assert (4, 5) in records
