-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Before checking with .endswith, convert raw.filenames[0] to str in case it is a path #12840
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
Conversation
|
|
|
Do we need |
|
IMO it's the other way around, we should try to support Paths instead of str. Edit: Newer readers like the EyeLink or ANT explicitly cast to |
Ahh, thanks, found it: Lines 677 to 680 in f3a3ca4
|
Depends on how this property is used. I was thinking that it's just a list of filenames (usually there will be only one filename). I don't think that this is supposed to store the entire path, so I think a str would be the better choice. But correct me if I'm wrong if this attribute serves a different purpose. |
|
I think a tuple of Paths would be good, with additional documentation under: Lines 677 to 680 in f3a3ca4
That documentation could include that obtaining a str of the filename can be as easy as I think this would be more powerful than just having a tuple of str. |
|
I'd still like to know what purpose this attribute serves. As far as I can see, we don't really need it except to print the original file names in a report? So if this is not intended to be a path, why store it as a path? In any case, I'm not going to argue for it anymore. If you think a Can you also add type information in the class docstring (in addition to the property)? |
I sometimes use it in personal scripts of mine, to get info that I might store as part of a file path. There are other solutions I could use, of course ... but sometimes this is convenient.
I also don't have a strong opinion. Happy to follow the majority. |
|
IIRC, the purpose is to store the files needed to load data from when Line 254 in f3a3ca4
Which should convert all our reader code at once. However, we also need to track down lines like this one: Line 279 in f3a3ca4
Which needs to be converted.. |
That would be much appreciated 🙏 Your suggested changes sound good to me. I would still also improve the documentation of the attribute in the API docs, and perhaps also add a check to the property ( |
Can you point me to the corresponding code? I didn't find this when grepping for I think we should first establish what purpose this attribute serves, and only then decide what the best representation is. If it is merely for displaying the original file name (this is my best guess at the moment), then I'd go for a string, which is easier and we don't want/need any path-related info then (just the file name). |
|
It seems like most readers already use |
|
Here for the FIFF format: Lines 392 to 395 in f3a3ca4
The method |
|
Everything is using the private |
|
-1 for this since some readers are setting |
|
What about adding a setter that takes care of type conversion? Then we could use the public attribute instead of fiddling with the private one. |
|
I agree that would be cleaner, and removing the private attribute will let the unit test tell us where we need to now use the public property. I suspect that will turn out into a massive change.. while casting here where we set this private attribute will yield a smaller diff: Line 254 in f3a3ca4
I'll give it a shot, le's see how much it is. |
|
Why don't you use Path.name.endswith() or Path.as_posix().endswith()? |
For me it's more about wanting a consistent and documented The issue here only arises because it is sometimes one, and sometimes the other ... in particular in user-code or 3rd library code where people may set |
|
I'm almost done with a draft PR using |
ah got you! |
|
I ran into an issue when I tried to export a Raw object to EEGLAB and it expected
raw.filenames[0]to be a str, but it was a pathlib.Path.With the little fix here, such surprises will be minimized, at no real cost for mne, IMHO.
Furthermore, we do not specify in the API, what
raw.filenamesSHOULD be in terms of a datatype:https://mne.tools/stable/generated/mne.io.Raw.html#mne.io.Raw.filenames
Can somebody tell me the difference between
.filenamesand._filenames? For example @cbrnr you are using the private attribute here: https://github.com/cbrnr/mnelab/blob/f5f641ba4376e53f1d8687692b592aecb9beea8d/src/mnelab/io/xdf.py#L154What is your reasoning for that over using the public one?