-
Notifications
You must be signed in to change notification settings - Fork 0
feat: date sanity #131
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
Open
g-pechorin
wants to merge
8
commits into
main
Choose a base branch
from
feat.date-sanity
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
feat: date sanity #131
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
809de3c
allow csv in tests/data
peterlavalle-nhs c412122
checks dates are in a sane range
peterlavalle-nhs a4d39ba
marked places for the exceptions (to help with merge)
peterlavalle-nhs 7b9817f
Merge branch 'marks' into feat.date-sanity
peterlavalle-nhs 3f16f72
removed the marks
peterlavalle-nhs cbaa14a
Merge remote-tracking branch 'origin/main' into feat.date-sanity
peterlavalle-nhs dc196a9
Merge remote-tracking branch 'origin/main' into feat.date-sanity
peterlavalle-nhs ccba826
date range sanity checks now pass
peterlavalle-nhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ wheels/ | |
|
|
||
| # Output files | ||
| *.csv | ||
| *.xlsx | ||
| tests/output/ | ||
| *.jsonl | ||
| *.jsonl.gz | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| !*.csv | ||
| !*.xlsx |
Binary file not shown.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from nuh_helper import shift_excel_dates_inplace | ||
| from nuh_helper.date_shift import ( | ||
| DateTooFarAhead, | ||
| DateTooFarBack, | ||
| ) | ||
|
|
||
|
|
||
| def test_too_far_ahead(tmp_path: Path) -> None: | ||
|
|
||
| source_file = Path(__file__).parent / "data/date_sanity/too_far_ahead.xlsx" | ||
| output_path = tmp_path / "target.xlsx" | ||
| linking_table_old = tmp_path / "linking_table_old.csv" | ||
| linking_table_out = tmp_path / "linking_table_out.csv" | ||
|
|
||
| sheet_configs = { | ||
| "tofarr": { | ||
| "patient_id_col": "patient", | ||
| "date_columns": [ | ||
| "dobirth", | ||
| ], | ||
| "header_row": 0, | ||
| "skip_rows_after_header": [], | ||
| }, | ||
| } | ||
| with pytest.raises(DateTooFarAhead) as info: | ||
| shift_excel_dates_inplace( | ||
| input_file=str(source_file), | ||
| output_file=str(output_path), | ||
| patient_sheet="tofarr", | ||
| patient_id_col="patient", | ||
| sheet_configs=sheet_configs, | ||
| min_shift_days=-20, | ||
| max_shift_days=-1, | ||
| seed=14333, | ||
| linking_table_path=str(linking_table_old), | ||
| linking_table_output=str(linking_table_out), | ||
| ) | ||
|
|
||
| assert ( | ||
| info.value._message == "the date 2072-12-10 00:00:00 is too far in the future" | ||
| ) | ||
|
|
||
|
|
||
| def test_too_far_back(tmp_path: Path) -> None: | ||
|
|
||
| source_file = Path(__file__).parent / "data/date_sanity/too_far_back.xlsx" | ||
| output_path = tmp_path / "target.xlsx" | ||
| linking_table_old = tmp_path / "linking_table_old.csv" | ||
| linking_table_out = tmp_path / "linking_table_out.csv" | ||
|
|
||
| sheet_configs = { | ||
| "Sheet1": { | ||
| "patient_id_col": "patient", | ||
| "date_columns": [ | ||
| "dob", | ||
| ], | ||
| "header_row": 0, | ||
| "skip_rows_after_header": [], | ||
| }, | ||
| } | ||
| with pytest.raises(DateTooFarBack) as info: | ||
| shift_excel_dates_inplace( | ||
| input_file=str(source_file), | ||
| output_file=str(output_path), | ||
| patient_sheet="Sheet1", | ||
| patient_id_col="patient", | ||
| sheet_configs=sheet_configs, | ||
| min_shift_days=-20, | ||
| max_shift_days=-1, | ||
| seed=14333, | ||
| linking_table_path=str(linking_table_old), | ||
| linking_table_output=str(linking_table_out), | ||
| ) | ||
|
|
||
| assert info.value._message == "the date 1007-02-05 00:00:00 is too far in the past" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also needs adding to the readme