Skip to content

Commit

Permalink
fix: grouping by a single level that contains tuples resulted in seve…
Browse files Browse the repository at this point in the history
…ral levels in the resulting MultiIndex; this fix applied for completeness before the whole function is simplified
  • Loading branch information
johentsch committed Dec 11, 2023
1 parent 8f80fc2 commit 0ed6091
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/dimcat/data/resources/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,6 +2062,11 @@ def sort_transitions(df):
sorted_groups[antecedent_group] = pd.concat(
[sorted_consequents, proportions.rename("proportion")], axis=1
)
if isinstance(antecedent_group, tuple) and len(antecedent_group) > 1:
# in the case where each antecedent is a tuple, the 'levels' argument ensures that they are not turned
# into multiple index levels
keys = list(sorted_groups.keys())
return pd.concat(sorted_groups, levels=[keys], names=[antecedent])
return pd.concat(sorted_groups, names=[antecedent])

if group_cols:
Expand Down

0 comments on commit 0ed6091

Please sign in to comment.