Skip to content

Commit

Permalink
Merge branch 'main' into signals
Browse files Browse the repository at this point in the history
  • Loading branch information
hofaflo authored Dec 13, 2023
2 parents aa54cd3 + 2de61c5 commit 146f4ee
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### Changed
- Exclude EDF+ annotation signals from `Edf.signals`, `Edf.num_signals`, and `Edf.drop_signals()` ([#25](https://github.com/the-siesta-group/edfio/pull/25)).

### Added
- Expand `~` (tilde) to the user's home directory in `edf_file` argument of `read_edf()` and `target` argument of `Edf.write()` ([#23](https://github.com/the-siesta-group/edfio/pull/23)).

### 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)).
Expand Down
3 changes: 2 additions & 1 deletion edfio/edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def write(self, target: Path | str | io.BufferedWriter | io.BytesIO) -> None:
target.write(header_record)
target.write(data_record.tobytes())
else:
with target.open("wb") as file:
with target.expanduser().open("wb") as file:
file.write(header_record)
data_record.tofile(file)

Expand Down Expand Up @@ -1559,6 +1559,7 @@ def _read_edf(edf_file: Any) -> Edf:
@_read_edf.register
def _(edf_file: Path) -> Edf:
edf = object.__new__(Edf)
edf_file = edf_file.expanduser()
with edf_file.open("rb") as file:
edf._read_header(file)
edf._load_data(edf_file)
Expand Down
5 changes: 5 additions & 0 deletions tests/test_edf.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ def test_read_edf_str():
assert read_edf(str(EDF_FILE)).num_signals == 7


def test_read_edf_expanduser():
with pytest.raises(FileNotFoundError, match="^[^~]*$"):
read_edf("~/edfio_testfile_that_should_not_exist.edf")


@pytest.mark.parametrize("mode", ["rb", "r+b"])
def test_read_edf_file_object(mode):
with EDF_FILE.open(mode) as edf_file:
Expand Down

0 comments on commit 146f4ee

Please sign in to comment.