Skip to content

Commit 31a8ab6

Browse files
authored
Merge pull request #829 from effigies/enh/relax_groupby_rules
ENH: Relax group_by rules, allowing any entity to be used
2 parents e92d4e8 + bba7385 commit 31a8ab6

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

bids/modeling/statsmodels.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@
1818
import warnings
1919

2020

21-
# Only entities in this list can be used in grouping
22-
VALID_GROUPING_ENTITIES = {'run', 'session', 'subject', 'task', 'contrast'}
23-
24-
2521
def validate_model(model):
2622
"""Validate a BIDS-StatsModel structure.
2723
@@ -343,9 +339,7 @@ def _build_groups(objects, group_by):
343339

344340
# Single-run tasks and single-session subjects may not have entities
345341
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
342+
group_by = set(group_by) - dummy_groups
349343

350344
# Verify all columns in group_by exist and raise sensible error if not
351345
missing_vars = list(group_by - set(df.columns))
@@ -583,11 +577,7 @@ def __init__(self, node, entities={}, collections=None, inputs=None,
583577
if inputs:
584578
dfs.append(self._inputs_to_df(inputs))
585579

586-
# merge all the DataFrames into one DF to rule them all
587-
def merge_dfs(a, b):
588-
on = list(set(a.columns) & set(b.columns) & VALID_GROUPING_ENTITIES)
589-
return a.merge(b, on=on)
590-
df = reduce(merge_dfs, dfs)
580+
df = reduce(pd.DataFrame.merge, dfs)
591581

592582
var_names = list(self.node.model['x'])
593583

0 commit comments

Comments
 (0)