diff --git a/src/recordlinker/linkage/matchers.py b/src/recordlinker/linkage/matchers.py index 0c73662..d050176 100644 --- a/src/recordlinker/linkage/matchers.py +++ b/src/recordlinker/linkage/matchers.py @@ -101,6 +101,12 @@ def feature_match_exact( :return: A boolean indicating whether the features are an exact match. """ idx = col_to_idx[feature_col] + + # Convert datetime obj to str using helper function + if feature_col == "birthdate": + record_i[idx] = utils.datetime_to_str(record_i[idx]) + record_j[idx] = utils.datetime_to_str(record_j[idx]) + return record_i[idx] == record_j[idx] diff --git a/tests/unit/test_matchers.py b/tests/unit/test_matchers.py index 98de91f..857d767 100644 --- a/tests/unit/test_matchers.py +++ b/tests/unit/test_matchers.py @@ -159,16 +159,20 @@ def test_feature_match_four_char(): def test_feature_match_exact(): - record_i = [1, 0, -1, "blah", "", True] - record_j = [1, 0, -1, "blah", "", True] - record_k = [2, 10, -10, "no match", "null", False] + record_i = ["240 Rippin Ranch Apt 66", "1980-01-01", "Los Angeles", "Verónica Eva", "Reynoso", "834d436b-9e1f-2e8e-f28a-ad40bef9f365", "female", "CA", "90502"] + record_j = ["240 Rippin Ranch Apt 66", "1980-01-01", "Los Angeles", "Verónica Eva", "Reynoso", "834d436b-9e1f-2e8e-f28a-ad40bef9f365", "female", "CA", "90502"] + record_k = ["240 Rippin Ranch Apt 66", datetime.date(1980, 1, 1), "Los Angeles", "Verónica Eva", "Reynoso", "834d436b-9e1f-2e8e-f28a-ad40bef9f365", "female", "CA", "90502"] + record_l = ["123 X St Unit 2", "1995-06-20", "Chicago", "Alejandra", "Arenas", "124d436b-9e1f-2e8e-f28a-ad40bef9f367", "male", "IL", "60615"] + record_m = ["123 X St Unit 2", datetime.date(1980, 6, 20), "Chicago", "Alejandra", "Arenas", "124d436b-9e1f-2e8e-f28a-ad40bef9f367", "male", "IL", "60615"] - cols = {"col_1": 0, "col_2": 1, "col_3": 2, "col_4": 3, "col_5": 4, "col_6": 5} + cols = {"address": 0, "birthdate": 1, "city": 2, "first_name": 3, "last_name": 4, "mrn": 5, "sex": 6, "state": 7, "zip": 8} # Simultaneously test matches and non-matches of different data types for c in cols: assert matchers.feature_match_exact(record_i, record_j, c, cols) - assert not matchers.feature_match_exact(record_i, record_k, c, cols) + assert matchers.feature_match_exact(record_i, record_k, c, cols) + assert not matchers.feature_match_exact(record_i, record_l, c, cols) + assert not matchers.feature_match_exact(record_i, record_m, c, cols) # Special case for matching None--None == None is vacuous assert matchers.feature_match_exact([None], [None], "col_7", {"col_7": 0})