Use Path in raw.filenames and epochs.filename#12843
Use Path in raw.filenames and epochs.filename#12843larsoner merged 59 commits intomne-tools:mainfrom
Conversation
|
I'll pick this up tomorrow, let's see how much stuff breaks. I actually went further than my initial approach where now if |
larsoner
left a comment
There was a problem hiding this comment.
Okay @mscheltienne I finally figured it out, and added some comments along the way. Can you look then mark as ready and merge-when-green if you're also happy?
|
Failures on this and other PRs are just scipy/scipy#21623 and can be safely ignored (I think we can trust Windows pip-pre to continue being picky while the Linux pip-pre job fails in the dependencies step) |
mscheltienne
left a comment
There was a problem hiding this comment.
Looks straightforward 😆 The comments are very clear, thanks for finishing this one!
|
We are getting an error in mne-bids that may be related to this: https://github.com/mne-tools/mne-bids/actions/runs/11081048651/job/30792323679#step:16:416 It seems to be related to the list of Lines 96 to 116 in 5492174 with the eventual error being:
|
|
@mscheltienne is this expected behavior that I get an error here (on mne main)? # %%
from pathlib import Path
import numpy as np
import mne
# create a dummy raw
sampling_freq = 1000
times = np.linspace(0, 1, sampling_freq, endpoint=False)
sine = np.sin(20 * np.pi * times)
cosine = np.cos(10 * np.pi * times)
data = np.array([sine, cosine])
info = mne.create_info(
ch_names=["10 Hz sine", "5 Hz cosine"], ch_types=["misc"] * 2, sfreq=sampling_freq
)
raw = mne.io.RawArray(data, info)
# I want to set raw.filenames
a = Path.cwd() / "IDoNotExist.jpg"
# error: TypeError: 'tuple' object does not support item assignment
raw.filenames = (a,)
# this gives the right error: FileNotFoundError: File <...>/IDoNotExist.jpg not found.
raw.filenames = [a]
# this works correctly
#path_to_file_that_exists = ...
#raw.filenames = [path_to_file_that_exists]
# this works, no errors raised (which is ok, because I am using a private attribute to circumvent checks)
raw._filenames = (a,) |
Closes #12840
Attempting to use paths inside of
raw.filenamesandepochs.filenameattributes.Seems to work except for IO 'file-likes' with FIFF. It was a surprise to me that this was even possible, so I'm having a bit of an hard time getting this to work. Ideally, a file-like should not be listed in the filenames attribute which should then be set to
None. It isn't informative to display"File-Like"or therepr(...). At the same time, I don't understand howpreloadworks with afile-likeobject, since it needs thefile-likeobject inraw.filenamesto load the segments whenpreload=False.