Skip to content
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

[MRG] Fix copyfile_eeglab type conflicts #1126

Merged
merged 3 commits into from
Mar 8, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Detailed list of changes
^^^^^^^^^^^^

- Amending a dataset now works in cases where the newly-written data contains additional participant properties (new columns in ``participants.tsv``) not found in the existing dataset, by `Richard Höchenberger`_ (:gh:`1113`)
- Fixes :func:`~mne_bids.copyfiles.copyfile_eeglab` to prevent data type conversion leading to an ``eeg_checkset`` failure when trying to load the file in EEGLAB, by `Laetitia Fesselier`_ (:gh:`1122`)

:doc:`Find out what was new in previous releases <whats_new_previous_releases>`

Expand Down
5 changes: 3 additions & 2 deletions mne_bids/copyfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,18 +533,19 @@ def copyfile_eeglab(src, dest):
# structure and potentially breaks re-reading of the file
uint16_codec = None
eeg = loadmat(file_name=src, simplify_cells=False,
appendmat=False, uint16_codec=uint16_codec)
appendmat=False, uint16_codec=uint16_codec, mat_dtype=True)
sappelhoff marked this conversation as resolved.
Show resolved Hide resolved
oldstyle = False
if 'EEG' in eeg:
eeg = eeg['EEG']
oldstyle = True

has_fdt_link = False
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to revert this change, as it makes the program flow less obvious

Copy link
Contributor Author

@laemtl laemtl Mar 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the current implementation, there is some potential cases where has_fdt_link will not be set and an error thrown. It happened to me during testing so that's how I tried to fix that. Would you prefer an else case instead?

    try:
        # If the data field is a string, it points to a .fdt file in src dir
        if isinstance(eeg['data'][0, 0][0], str):
            has_fdt_link = True
        else:
            has_fdt_link = False
    except IndexError:
        has_fdt_link = False

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me both ways are fine. Thanks for figuring out that there is one potential flow that previously lead to an error!

try:
# If the data field is a string, it points to a .fdt file in src dir
if isinstance(eeg['data'][0, 0][0], str):
has_fdt_link = True
except IndexError:
has_fdt_link = False
pass

if has_fdt_link:
fdt_fname = eeg['data'][0, 0][0]
Expand Down