-
Notifications
You must be signed in to change notification settings - Fork 90
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
[MRG] Raise an error message when src==dest in write_raw_bids #889
Conversation
@adam2392 let me know when it's good to go from your end |
Ugh million tests to change cuz of write_edf... |
1 similar comment
Ugh million tests to change cuz of write_edf... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we solve this without raising an error? For example by:
- moving the "file removal in case of overwriting" step further below
- then being able to check whether removal would result in an impossible copyfile call
- and if that IS the case, do a temp backup copy before removal
- then use the temp backup copy for the copyfile call
- finally delete the temp backup copy
I don't think you should switch to |
What's the status here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR wants to do:
1 Adds an error for src == dest during write_raw_bids
2 Changes writing of EDF to use _write_raw_edf, since EDFlib-Python is a supported EDF writer now
3 Adds a unit test to track this behavior
I think point 2 should be dropped from this PR and (if at all) be done in a separate PR. I say "if at all", because
I don't think you should switch to _write_edf. We want to just copy the files in order to manipulate the raw files themselves as little as possible :-)
(see #889 (comment) and #889 (comment))
Regarding point 1 and 3: Yes, +1 to do this. Having an explicit (and covered) error for this scenario would be an improvement over the status quo. But that error doesn't need to be a big and advertised thing, and not framed as a "limitation of mne-bids" IMHO (see #889 (comment))
All in all, I think this PR could be fixed with a small couple of lines to
- detect the copy issue scenario
- raise a small error that we don't support that
- add a test to trigger that error
Codecov Report
@@ Coverage Diff @@
## main #889 +/- ##
==========================================
- Coverage 95.19% 95.16% -0.03%
==========================================
Files 25 25
Lines 3787 3786 -1
==========================================
- Hits 3605 3603 -2
- Misses 182 183 +1
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready for review, not that I also bumped minimum requirements for mne to 1.0 -- wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all good, except for changes to the docstring of BIDSPath, and the type of an exception you're raising
else: | ||
bids_path.fpath.unlink() | ||
else: | ||
raise FileExistsError( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this line never hit by tests? should get coverage IMHO
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The line is tested somewhat here:
mne-bids/mne_bids/tests/test_write.py
Lines 1858 to 1866 in 213c378
# proceed with the actual test for EEGLAB data | |
write_raw_bids(raw, bids_path, overwrite=False) | |
read_raw_bids(bids_path=bids_path) | |
with pytest.raises(TypeError, match="unexpected keyword argument 'foo'"): | |
read_raw_bids(bids_path=bids_path, extra_params=dict(foo='bar')) | |
with pytest.raises(FileExistsError, match="already exists"): # noqa: F821 | |
write_raw_bids(raw, bids_path, overwrite=False) |
The reason it is never hit is because other files (like events.tsv) get written earlier than the neural data file in write_raw_bids
, and these raise an identical error:
Lines 206 to 207 in 213c378
raise FileExistsError(f'"{fname}" already exists. ' | |
'Please set overwrite to True.') |
(... but in a different line)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So … then we can just remove this else
branch, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd leave it here. People may manually remove all other files and then this line would reasonably trigger. it's just not covered in our tests, which I find okay (and which I did not introduce here) :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alright, let's leave it here then!
Thanks, @sappelhoff! |
PR Description
Closes: #867
_write_raw_edf
, since EDFlib-Python is a supported EDF writer nowThe reason we can't accommodate copying files is outlined in the issue.
Merge checklist
Maintainer, please confirm the following before merging: