moabb
moabb copied to clipboard
UnicodeEncodeError when caching intermediate data: 'gbk' codec can't encode '\xef'
Description
On Windows, caching fails with UnicodeEncodeError when writing metadata YAML and participants_tsv .
Error
UnicodeEncodeError: 'gbk' codec can't encode character '\xef' in position 2... Traceback:
################### Exception: ###################
Traceback (most recent call last):
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\base.py", line 1170, in _get_single_subject_data_using_cache
interface.save(sessions_data)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\bids_interface.py", line 2475, in save
self._write_file(bids_path, obj)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\bids_interface.py", line 2690, in _write_file
_update_participants_tsv(bids_path.root, self.subject, metadata, raw=raw)
~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\bids_interface.py", line 968, in _update_participants_tsv
writer.writerows(rows)
~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\csv.py", line 229, in writerows
return self.writer.writerows(map(self._dict_to_list, rowdicts))
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'gbk' codec can't encode character '\xef' in position 61: illegal multibyte sequence
##################################################
################### Exception: ###################
Traceback (most recent call last):
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\base.py", line 1170, in _get_single_subject_data_using_cache
interface.save(sessions_data)
~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\bids_interface.py", line 2500, in save
_write_metadata_yaml(self.root, self.dataset)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Shengle\anaconda3\envs\mne\Lib\site-packages\moabb\datasets\bids_interface.py", line 1381, in _write_metadata_yaml
yaml.dump(
~~~~~~~~~^
data,
^^^^^
...<4 lines>...
width=120,
^^^^^^^^^^
)
^
...
Environment
Windows 11 (Chinese locale), Python 3.13.12, MOABB latest.
Suggestion
Open file with encoding='utf-8' instead of relying on system default GBK.
can you please give the minimal code to reproduce?
can you please give the minimal code to reproduce?
from moabb.evaluations import CrossSubjectEvaluation
from moabb.paradigms import SSVEP
from moabb.datasets import Wang2016
from sklearn.pipeline import make_pipeline
from moabb.pipelines import SSVEP_CCA
default_cache_config = {
"save_raw": True,
"save_epochs": False,
"save_array": False,
"use": True,
"overwrite_raw": True,
"overwrite_epochs": False,
"overwrite_array": False,
"path": None,
}
method_name = "CCA"
print(method_name, "Processing")
dataset = Wang2016()
dataset.subject_list = dataset.subject_list[:2]
selected_channels = ['O1', 'Oz', 'O2'][:1]
freq_map = {0: 10.0, 1: 10.2, 2: 10.4, 3: 10.6, 4: 10.8, 5: 11.0, 6: 11.2, 7: 11.4, 8: 11.6, 9: 11.8, 10: 12.0, 11: 12.2, 12: 12.4, 13: 12.6, 14: 12.8, 15: 13.0, 16: 13.2, 17: 13.4, 18: 13.6, 19: 13.8, 20: 14.0, 21: 14.2, 22: 14.4, 23: 14.6, 24: 14.8, 25: 15.0, 26: 15.2, 27: 15.4, 28: 15.6, 29: 15.8, 30: 8.0, 31: 8.2, 32: 8.4, 33: 8.6, 34: 8.8, 35: 9.0, 36: 9.2, 37: 9.4, 38: 9.6, 39: 9.8}
datasets = [dataset]
paradigm = SSVEP(channels=selected_channels)
pipelines = {}
pipelines[method_name] = make_pipeline(SSVEP_CCA(n_harmonics=3, freq_map=freq_map))
evalution = CrossSubjectEvaluation(datasets=datasets, paradigm=paradigm, overwrite=True, n_jobs=-1, cache_config=default_cache_config)
results = evalution.process(pipelines=pipelines)
okay okay, thanks!