File tree Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Expand file tree Collapse file tree 2 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -337,21 +337,24 @@ def _build_groups(objects, group_by):
337337
338338 groups = defaultdict (list )
339339
340- # sanitize grouping entities, otherwise weird things can happen
341- group_by = list (set (group_by ) & VALID_GROUPING_ENTITIES )
342-
343340 # Get unique values in each grouping variable and construct indexing DF
344341 entities = [obj .entities for obj in objects ]
345342 df = pd .DataFrame .from_records (entities )
346343
344+ # Single-run tasks and single-session subjects may not have entities
345+ dummy_groups = {"run" , "session" } - set (df .columns )
346+
347+ # sanitize grouping entities, otherwise weird things can happen
348+ group_by = set (group_by ) & VALID_GROUPING_ENTITIES - dummy_groups
349+
347350 # Verify all columns in group_by exist and raise sensible error if not
348- missing_vars = list (set ( group_by ) - set (df .columns ))
351+ missing_vars = list (group_by - set (df .columns ))
349352 if missing_vars :
350353 raise ValueError ("group_by contains variable(s) {} that could not "
351354 "be found in the entity index." .format (missing_vars ) )
352355
353356 # Restrict DF to only grouping columns
354- df = df .loc [:, group_by ]
357+ df = df .loc [:, list ( group_by ) ]
355358
356359 unique_vals = {col : df [col ].dropna ().unique ().tolist () for col in group_by }
357360
Original file line number Diff line number Diff line change @@ -105,7 +105,9 @@ def test_entire_graph_smoketest(graph):
105105 # At dataset level, do one-sample t-tests separately for each gender,
106106 # but also two-sample t-tests comparing males and females.
107107 # Note that there are only 2 subjects in the graph.
108- outputs = graph ["run" ].run (group_by = ['subject' , 'run' ])
108+ # Note also that there is only one session (with no session label), which
109+ # should have no effect as a grouping variable
110+ outputs = graph ["run" ].run (group_by = ['subject' , 'session' , 'run' ])
109111 # 2 subjects x 3 runs
110112 assert len (outputs ) == 6
111113 cis = list (chain (* [op .contrasts for op in outputs ]))
You can’t perform that action at this time.
0 commit comments