Repository navigation
Closed
Closed
Copy link
Labels
Description
Description of the problem
The below does not happen if you use a version of pymatreader with my fix https://gitlab.com/obob/pymatreader/-/merge_requests/56
>>> eeg = read_raw_eeglab("/path/to/my/eeglab.set")
Traceback (most recent call last):
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 16, in _todict_from_np_struct
n_items = len(data[cur_field_name])
TypeError: len() of unsized object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 16, in _todict_from_np_struct
n_items = len(data[cur_field_name])
TypeError: len() of unsized object
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
eeg = read_raw_eeglab("/home/frankier/rse/hipercog/PSICAT/prc/TAPPED/1_load/1060P_psicat_intake.set")
File "/home/frankier/sources/mne-python/mne/io/eeglab/eeglab.py", line 331, in read_raw_eeglab
return RawEEGLAB(
input_fname=input_fname,
...<4 lines>...
verbose=verbose,
)
File "<decorator-gen-218>", line 12, in __init__
File "/home/frankier/sources/mne-python/mne/io/eeglab/eeglab.py", line 451, in __init__
eeg = _check_load_mat(input_fname, uint16_codec, preload=preload)
File "/home/frankier/sources/mne-python/mne/io/eeglab/eeglab.py", line 78, in _check_load_mat
eeg = _readmat(fname, uint16_codec=uint16_codec, preload=preload)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 164, in _readmat
return read_mat(fname, uint16_codec=uint16_codec)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 83, in _scipy_reader
return _check_for_scipy_mat_struct(mat_data)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 57, in _check_for_scipy_mat_struct
data[key] = _check_for_scipy_mat_struct(data[key])
~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 67, in _check_for_scipy_mat_struct
data = _handle_scipy_ndarray(data)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 42, in _handle_scipy_ndarray
data = _todict_from_np_struct(data)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 27, in _todict_from_np_struct
cur_value = _check_for_scipy_mat_struct(cur_value)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 67, in _check_for_scipy_mat_struct
data = _handle_scipy_ndarray(data)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 42, in _handle_scipy_ndarray
data = _todict_from_np_struct(data)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 27, in _todict_from_np_struct
cur_value = _check_for_scipy_mat_struct(cur_value)
File "/home/frankier/sources/mne-python/mne/io/eeglab/_eeglab.py", line 61, in _check_for_scipy_mat_struct
if data[0][2] == b"string":
^^^^^^^^^^^^^^^^^^^^^^^
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
This could probably be fixed by porting the fix in the linked PR. However I'm wondering whether it would be possible to just depend upon pymatreader and remove the non-pymatreader code path?
Steps to reproduce
Load an EEGLab file without pymatreader installed but with SciPy 1.18Link to data
No response
Expected results
It works
Actual results
An exception
Additional information
An exception
Activity
larsoner commentedon Sep 10, 2026
We could think about this route but it does potentially mean more deps / work for end users (though pymatreader is pretty lightweight). Either way they'd need latest
pymatreaderas of your PR being merged 2 weeks ago right?My inclination is to fix this so that
scipy.ioworks as well. We should fix this gap in testing coverage, too... SciPy 1.18 has been out a while, we should have caught this sooner.@frankier do you want to look? If not I can do it
frankier commentedon Sep 10, 2026
Yes they'd need the latest pymatreader which I made sure is compatible with both old and new versions of SciPy. It seems like a fine dependency to me -- the maintainer was pretty responsive at least. It could simply be made a compulsory requirement if the idea is that EEGLab reading should work out of the box. If you like, I could prepare a PR for this. (Of course this could surface extra reasons against, but I think it's worth a try.)
I understand you position, but I won't prepare a PR in this case (but please go ahead yourself). I think the fact it wasn't caught in testing kind of shows the problem in a way since now there are 2* as many configurations (with/without pymatreader).