Skip to content

Commit d602f8c

Browse files
authored
fix overwrite for CTF in write_raw_bids (#791)
* fix overwrite for CTF in write_raw_bids * update what's new
1 parent 12815db commit d602f8c

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

doc/whats_new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Bug fixes
6161
- The :class:`mne.Annotations` ``BAD_ACQ_SKIP`` – added by the acquisition system to ``FIFF`` files – will now be preserved when reading raw data, even if these time periods are **not** explicitly included in ``*_events.tsv``, by `Richard Höchenberger`_ and `Alexandre Gramfort`_ (:gh:`754` and :gh:`762`)
6262
- :func:`mne_bids.write_raw_bids` will handle different cased extensions for EDF files, such as `.edf` and `.EDF` by `Adam Li`_ (:gh: `765`)
6363
- :func:`mne_bids.inspect_dataset` didn't handle certain filenames correctly on some systems, by `Richard Höchenberger`_ (:gh:`769`)
64+
- :func:`mne_bids.write_raw_bids` now works across data types with ``overwrite=True``, by `Alexandre Gramfort`_ (:gh:`791`)
6465

6566
:doc:`Find out what was new in previous releases <whats_new_previous_releases>`
6667

mne_bids/tests/test_write.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,7 @@ def test_ctf(_bids_validate, tmpdir):
851851
raw = _read_raw_ctf(raw_fname)
852852
raw.info['line_freq'] = 60
853853
write_raw_bids(raw, bids_path)
854+
write_raw_bids(raw, bids_path, overwrite=True) # test overwrite
854855

855856
_bids_validate(tmpdir)
856857
with pytest.warns(RuntimeWarning, match='Did not find any events'):

mne_bids/write.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,10 +1344,16 @@ def write_raw_bids(raw, bids_path, events_data=None,
13441344
# create parent directories if needed
13451345
_mkdir_p(os.path.dirname(data_path))
13461346

1347-
if os.path.exists(bids_path.fpath) and not overwrite:
1348-
raise FileExistsError(
1349-
f'"{bids_path.fpath}" already exists. ' # noqa: F821
1350-
'Please set overwrite to True.')
1347+
if os.path.exists(bids_path.fpath):
1348+
if overwrite:
1349+
if bids_path.fpath.is_dir():
1350+
shutil.rmtree(bids_path.fpath)
1351+
else:
1352+
bids_path.fpath.unlink()
1353+
else:
1354+
raise FileExistsError(
1355+
f'"{bids_path.fpath}" already exists. ' # noqa: F821
1356+
'Please set overwrite to True.')
13511357

13521358
# If not already converting for anonymization, we may still need to do it
13531359
# if current format not BIDS compliant

0 commit comments

Comments
 (0)