Skip to content

Commit

Permalink
ENH: Relax group_by rules, allowing any entity to be used
Browse files Browse the repository at this point in the history
  • Loading branch information
effigies committed Mar 29, 2022
1 parent e92d4e8 commit bba7385
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions bids/modeling/statsmodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@
import warnings


# Only entities in this list can be used in grouping
VALID_GROUPING_ENTITIES = {'run', 'session', 'subject', 'task', 'contrast'}


def validate_model(model):
"""Validate a BIDS-StatsModel structure.
Expand Down Expand Up @@ -343,9 +339,7 @@ def _build_groups(objects, group_by):

# Single-run tasks and single-session subjects may not have entities
dummy_groups = {"run", "session"} - set(df.columns)

# sanitize grouping entities, otherwise weird things can happen
group_by = set(group_by) & VALID_GROUPING_ENTITIES - dummy_groups
group_by = set(group_by) - dummy_groups

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

# merge all the DataFrames into one DF to rule them all
def merge_dfs(a, b):
on = list(set(a.columns) & set(b.columns) & VALID_GROUPING_ENTITIES)
return a.merge(b, on=on)
df = reduce(merge_dfs, dfs)
df = reduce(pd.DataFrame.merge, dfs)

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

Expand Down

0 comments on commit bba7385

Please sign in to comment.