-
Notifications
You must be signed in to change notification settings - Fork 0
feat: date detection #130
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
Merged
Merged
feat: date detection #130
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
809de3c
allow csv in tests/data
peterlavalle-nhs fe761b4
testing to find hidden dates
peterlavalle-nhs 1a027e7
prints the cell content
peterlavalle-nhs 3e4e151
it detects the dates
peterlavalle-nhs 8b04f63
Merge branch 'main' into feat.date-detect
g-pechorin a4d39ba
marked places for the exceptions (to help with merge)
peterlavalle-nhs a91b04b
Merge branch 'marks' into feat.date-detect
peterlavalle-nhs bc865e7
removes the marking blocks
peterlavalle-nhs d13a413
Merge branch 'main' into feat.date-detect
g-pechorin 8e8feb2
Merge branch 'main' into feat.date-detect
g-pechorin 746bd92
updates tests - can't hide dates in passthrough tests (oops)
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
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.
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,122 @@ | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from nuh_helper import shift_excel_dates_inplace | ||
| from nuh_helper.date_shift import ( | ||
| HiddenDate, | ||
| ) | ||
|
|
||
|
|
||
| def test_iso8601(tmp_path: Path) -> None: | ||
|
|
||
| source_file = Path(__file__).parent / "data/hidden_dates/iso8601.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 = { | ||
| "args": { | ||
| "patient_id_col": "ptid", | ||
| "date_columns": [ | ||
| "dob", | ||
| ], | ||
| "header_row": 0, | ||
| "skip_rows_after_header": [], | ||
| }, | ||
| } | ||
| with pytest.raises(HiddenDate) as info: | ||
| shift_excel_dates_inplace( | ||
| input_file=str(source_file), | ||
| output_file=str(output_path), | ||
| patient_sheet="args", | ||
| patient_id_col="ptid", | ||
| 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 == ( | ||
| "hidden date in [sheet_name='args', 4, 3]" | ||
| + " value='hives on 2023-10-12'" | ||
| + " // found=datetime.datetime(2023, 10, 12, 0, 0)" | ||
| ) | ||
|
|
||
|
|
||
| def test_us_date(tmp_path: Path) -> None: | ||
|
|
||
| source_file = Path(__file__).parent / "data/hidden_dates/us_date.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 = { | ||
| "data": { | ||
| "patient_id_col": "ptid", | ||
| "date_columns": [ | ||
| "dob", | ||
| ], | ||
| "header_row": 0, | ||
| "skip_rows_after_header": [], | ||
| }, | ||
| } | ||
| with pytest.raises(HiddenDate) as info: | ||
| shift_excel_dates_inplace( | ||
| input_file=str(source_file), | ||
| output_file=str(output_path), | ||
| patient_sheet="data", | ||
| patient_id_col="ptid", | ||
| 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 == ( | ||
| "hidden date in [sheet_name='data', 6, 3]" | ||
| + ' value="can\'t recall the date but on 12/11/2001 they had an itchy tummy"' | ||
| + " // found=datetime.datetime(2001, 12, 11, 0, 0)" | ||
| ) | ||
|
|
||
|
|
||
| def test_written(tmp_path: Path) -> None: | ||
|
|
||
| source_file = Path(__file__).parent / "data/hidden_dates/written.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 = { | ||
| "yeah": { | ||
| "patient_id_col": "ptid", | ||
| "date_columns": [ | ||
| "dob", | ||
| ], | ||
| "header_row": 0, | ||
| "skip_rows_after_header": [], | ||
| }, | ||
| } | ||
| with pytest.raises(HiddenDate) as info: | ||
| shift_excel_dates_inplace( | ||
| input_file=str(source_file), | ||
| output_file=str(output_path), | ||
| patient_sheet="yeah", | ||
| patient_id_col="ptid", | ||
| 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 == ( | ||
| "hidden date in [sheet_name='yeah', 5, 3]" | ||
| + " value='flu on mar 21st, 2009'" | ||
| + " // found=datetime.datetime(2009, 3, 21, 0, 0)" | ||
| ) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.