Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(match): normalize DOB type #34

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions src/recordlinker/linkage/matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]


Expand Down
14 changes: 9 additions & 5 deletions tests/unit/test_matchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
Loading