Skip to content

Commit

Permalink
add participant data sanitizing
Browse files Browse the repository at this point in the history
  • Loading branch information
thht committed Sep 25, 2024
1 parent c0f2f06 commit 19b3c8e
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions mne_bids/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,27 @@ def _participants_tsv(raw, subject_id, fname, overwrite=False):
}
)

# Make sure that all entries to data are lists that
# contain scalars (i.e. not further lists). Fix if possible
for key in data.keys():
cur_value = data[key]
if not isinstance(cur_value, list):
cur_value = [cur_value]

# Check if all values are scalars
new_value = []
for cur_item in cur_value:
if isinstance(cur_item, list | tuple | np.ndarray):
if len(cur_item) == 1:
new_value.append(cur_item[0])
else:
raise ValueError(f"Value for key {key} is a list with more "
f"than one element. This is not supported.")
else:
new_value.append(cur_item)

data[key] = new_value

if os.path.exists(fname):
orig_data = _from_tsv(fname)
# whether the new data exists identically in the previous data
Expand Down

0 comments on commit 19b3c8e

Please sign in to comment.