Skip to content

Commit

Permalink
refactor: use enumerate instead of manually incremented index (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbelak-dtml authored Nov 16, 2023
1 parent c7273c6 commit 2198954
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions edvart/report_sections/group_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,14 @@ def group_barplot(

# Choose color palette
colors = cl.scales["9"]["qual"]["Set1"]
color_idx = 0

fig = go.Figure()
for idx, row in pivot.iterrows():
for color_idx, (idx, row) in enumerate(pivot.iterrows()):
if hasattr(idx, "__len__") and not isinstance(idx, str):
group_name = "_".join([str(i) for i in idx])
else:
group_name = idx
color = colors[color_idx % len(colors)]
color_idx += 1
fig.add_trace(
go.Bar(
x=pivot.columns,
Expand Down Expand Up @@ -632,7 +630,6 @@ def overlaid_histograms(
)
# Choose color palette
colors = cl.scales["9"]["qual"]["Set1"]
color_idx = 0

# Distribution plot
fig = make_subplots(
Expand All @@ -643,15 +640,12 @@ def overlaid_histograms(
vertical_spacing=0.02,
)

for name, group in df.groupby(
by=(groupby[0] if isinstance(groupby, list) and len(groupby) == 1 else groupby)
):
for color_idx, (name, group) in enumerate(df.groupby(groupby)):
if hasattr(name, "__len__") and not isinstance(name, str):
group_name = "_".join([str(i) for i in name])
else:
group_name = name
color = colors[color_idx % len(colors)]
color_idx += 1
# Add to boxplot
fig.add_trace(
go.Box(
Expand Down

0 comments on commit 2198954

Please sign in to comment.