Skip to content

Commit

Permalink
Merge pull request #19 from the-siesta-group/read-non-uppercase-month
Browse files Browse the repository at this point in the history
Allow reading EDF+ startdate with non-uppercase month
  • Loading branch information
marcoross authored Dec 12, 2023
2 parents ae65ceb + 489ef46 commit 4a8b2d3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixed
- Avoid floating point errors sometimes preventing the creation of an Edf with signals that are actually compatible in duration ([#15](https://github.com/the-siesta-group/edfio/pull/15)).
- Allow reading EDF+ startdate and birthdate with non-uppercase month ([#19](https://github.com/the-siesta-group/edfio/pull/19)).

## [0.3.1] - 2023-12-06

Expand Down
2 changes: 1 addition & 1 deletion edfio/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class FloatRange(NamedTuple):
def decode_edfplus_date(date: str) -> datetime.date:
day, month, year = date.split("-")
try:
month_int = _MONTH_NAMES.index(month) + 1
month_int = _MONTH_NAMES.index(month.upper()) + 1
except ValueError:
raise ValueError(f"Invalid month: {month}, options: {_MONTH_NAMES}") from None
return datetime.date(int(year), month_int, int(day))
Expand Down
12 changes: 12 additions & 0 deletions tests/test_edfplus_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ def test_patient_birthdate_raises_error_if_not_available():
patient.birthdate


@pytest.mark.parametrize("birthdate", ["01-Nov-2023", "01-nov-2023", "01-noV-2023"])
def test_patient_birthdate_incorrect_case(birthdate: str):
patient = Patient._from_str(f"X X {birthdate} X")
assert patient.birthdate == datetime.date(2023, 11, 1)


def test_patient_allows_accessing_other_fields_if_birthdate_is_invalid():
patient = Patient._from_str("X F 1-2-3 X")
assert patient.sex == "F"
Expand Down Expand Up @@ -161,6 +167,12 @@ def test_recording_startdate_raises_error_on_invalid_recording_field(
recording.startdate


@pytest.mark.parametrize("startdate", ["01-Nov-2023", "01-nov-2023", "01-noV-2023"])
def test_read_startdate_incorrect_case(startdate: str):
recording = Recording._from_str(f"Startdate {startdate} X X X")
assert recording.startdate == datetime.date(2023, 11, 1)


def test_recording_allows_accessing_other_fields_if_startdate_is_invalid():
recording = Recording._from_str("Startdate 1-2-3 EMG561 X X")
assert recording.hospital_administration_code == "EMG561"
Expand Down

0 comments on commit 4a8b2d3

Please sign in to comment.