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

Conversation

effigies
Copy link
Member

Do we have a good dataset to test this? It showed up with blip-up/blip-down, presumably single volume field maps.

Closes #598.

@effigies
Copy link
Member Author

@bkraft4257 Is there any chance you could give this a shot and verify that it solves your issue?

git clone git@github.com:effigies/fmriprep.git
cd fmriprep
git checkout fix/flatten
fmriprep-docker -f fmriprep [...]

Where [...] is the rest of your command.

@@ -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.

@effigies effigies requested a review from chrisgorgo July 26, 2017 13:36
@effigies effigies changed the title FIX: Ensure un-nested lists are not over-flattened [RTM] FIX: Ensure un-nested lists are not over-flattened Jul 27, 2017
Copy link
Member

@oesteban oesteban left a comment

Choose a reason for hiding this comment

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

I think we should merge this

@effigies effigies merged commit ad72b98 into nipreps:master Jul 28, 2017
@effigies effigies deleted the fix/flatten branch July 28, 2017 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants