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

Correct handling of unborns in 8535Q #480

Merged
merged 1 commit into from
May 22, 2024
Merged
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
20 changes: 11 additions & 9 deletions cin_validator/rules/cin2022_23/rule_8535Q.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

ChildIdentifiers = CINTable.ChildIdentifiers
PersonBirthDate = ChildIdentifiers.PersonBirthDate
ExpectedPersonBirthDate = ChildIdentifiers.ExpectedPersonBirthDate
PersonDeathDate = ChildIdentifiers.PersonDeathDate
LAchildID = ChildIdentifiers.LAchildID

Expand All @@ -29,11 +28,10 @@ def validate(

# Remove all rows with no deathdate
df = df[~df[PersonDeathDate].isna()]
# Remove children who died unborn. They shouldn't flag this rule [DfE tool doesn't].
df = df[~(df[ExpectedPersonBirthDate] > df[PersonDeathDate])]

# Return rows where DOB is prior to DOD
condition1 = df[PersonBirthDate] > df[PersonDeathDate]
# Return rows with no DOB
condition2 = df[PersonBirthDate].isna()

# df with all rows meeting the conditions
Expand Down Expand Up @@ -79,9 +77,8 @@ def test_validate():
{
"LAchildID": "child4",
"PersonDeathDate": "26/05/2000",
"ExpectedPersonBirthDate": "27/05/2000",
"PersonBirthDate": pd.NA,
# 3 pass: no birth date
# 3 fail: no birth date
},
{
"LAchildID": "child5",
Expand All @@ -102,9 +99,6 @@ def test_validate():
child_identifiers[PersonBirthDate] = pd.to_datetime(
child_identifiers[PersonBirthDate], format="%d/%m/%Y", errors="coerce"
)
child_identifiers[ExpectedPersonBirthDate] = pd.to_datetime(
child_identifiers[ExpectedPersonBirthDate], format="%d/%m/%Y", errors="coerce"
)

result = run_rule(validate, {ChildIdentifiers: child_identifiers})

Expand All @@ -117,7 +111,7 @@ def test_validate():
assert issue_columns == [PersonDeathDate, PersonBirthDate]

issue_rows = issues.row_df
assert len(issue_rows) == 2
assert len(issue_rows) == 3
assert isinstance(issue_rows, pd.DataFrame)
assert issue_rows.columns.to_list() == ["ERROR_ID", "ROW_ID"]

Expand All @@ -131,6 +125,14 @@ def test_validate():
),
"ROW_ID": [2],
},
{
"ERROR_ID": (
"child4",
pd.to_datetime("26/05/2000", format="%d/%m/%Y", errors="coerce"),
pd.to_datetime(pd.NA, format="%d/%m/%Y", errors="coerce"),
),
"ROW_ID": [3],
},
{
"ERROR_ID": (
"child5",
Expand Down
Loading