Skip to content

[RTM] FIX: Ensure un-nested lists are not over-flattened #602

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

Merged
merged 1 commit into from
Jul 28, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion fmriprep/workflows/fieldmap/unwarp.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ def init_prepare_epi_wf(ants_nthreads, name="prepare_epi_wf"):
workflow = pe.Workflow(name=name)

def _flatten(l):
return [item for sublist in l for item in sublist]
from niworkflows.nipype.utils.filemanip import filename_to_list
return [item for sublist in l for item in filename_to_list(sublist)]
Copy link
Member Author

Choose a reason for hiding this comment

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

Guess I'll just request a review. So the situation is that the input to merge from split is being interpreted as a list of single-character strings.

Given that the output is passed to _flatten before being passed to merge, I believe the correct interpretation is that we get a list with a single element ['/path/to/file']. Expanding that out:

[item for sublist in ['/path/to/file'] for item in sublist]
[item for item in '/path/to/file']
['/', 'p', 'a', 't', 'h', '/', 't', 'o', '/', 'f', 'i', 'l', 'e']

Thus, by using filename_to_list in the inner loop, we get:

[item for sublist in ['/path/to/file'] for item in filename_to_list(sublist)]
[item for item in filename_to_list('/path/to/file')]
[item for item in ['/path/to/file']]
['/path/to/file']

I believe that because this is the output of a MapNode, the original input must always be a list, so there's no concern about l itself being a string. However, we could be more cautious for basically no cost and apply filename_to_list at both the inner and outer loops.


workflow.connect([
(inputnode, split, [('fmaps', 'in_file')]),
Expand Down