Skip to content

Commit

Permalink
BUG: Fix bug with parent dir check
Browse files Browse the repository at this point in the history
  • Loading branch information
larsoner committed Dec 8, 2023
1 parent 59e5024 commit 8ce2e3f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions doc/changes/devel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ Bugs
- Allow :func:`mne.viz.plot_compare_evokeds` to plot eyetracking channels, and improve error handling (:gh:`12190` by `Scott Huberty`_)
- Fix bug with accessing the last data sample using ``raw[:, -1]`` where an empty array was returned (:gh:`12248` by `Eric Larson`_)
- Remove incorrect type hints in :func:`mne.io.read_raw_neuralynx` (:gh:`12236` by `Richard Höchenberger`_)
- Fix bug where parent directory existence was not checked properly in :meth:`mne.io.Raw.save` (:gh:`12282` by `Eric Larson`_)
- ``defusedxml`` is now an optional (rather than required) dependency and needed when reading EGI-MFF data, NEDF data, and BrainVision montages (:gh:`12264` by `Eric Larson`_)

API changes
Expand Down
7 changes: 7 additions & 0 deletions mne/io/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,13 @@ def set_annotations(self, annotations):
def _write_raw(raw_fid_writer, fpath, split_naming, overwrite):
"""Write raw file with splitting."""
dir_path = fpath.parent
_check_fname(
dir_path,
overwrite="read",
must_exist=True,
name="parent directory",
need_dir=True,
)
# We have to create one extra filename here to make the for loop below happy,
# but it will raise an error if it actually gets used
split_fnames = _make_split_fnames(
Expand Down
4 changes: 4 additions & 0 deletions mne/io/fiff/tests/test_raw_fiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,10 @@ def test_io_raw(tmp_path):
sl = slice(inds[0], inds[1])
assert_allclose(data[:, sl], raw[:, sl][0], rtol=1e-6, atol=1e-20)

# missing dir raises informative error
with pytest.raises(FileNotFoundError, match="parent directory does not exist"):
raw.save(tmp_path / "foo" / "test_raw.fif", split_size="1MB")


@pytest.mark.parametrize(
"fname_in, fname_out",
Expand Down

0 comments on commit 8ce2e3f

Please sign in to comment.