From 1dbf265596fcddc0396cc28470af9cdbf2a77009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bel=C3=A1k?= Date: Wed, 15 Nov 2023 11:10:20 +0100 Subject: [PATCH 1/2] refactor: use enumerate instead of manually incremented index --- edvart/report_sections/group_analysis.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/edvart/report_sections/group_analysis.py b/edvart/report_sections/group_analysis.py index ed12aa6..a751610 100644 --- a/edvart/report_sections/group_analysis.py +++ b/edvart/report_sections/group_analysis.py @@ -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, @@ -632,7 +630,6 @@ def overlaid_histograms( ) # Choose color palette colors = cl.scales["9"]["qual"]["Set1"] - color_idx = 0 # Distribution plot fig = make_subplots( @@ -643,15 +640,13 @@ 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( From 6496eb7ea8a77fd43bb6b1fd1e2e052676bca290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bel=C3=A1k?= Date: Thu, 16 Nov 2023 10:12:10 +0100 Subject: [PATCH 2/2] format with black --- edvart/report_sections/group_analysis.py | 1 - 1 file changed, 1 deletion(-) diff --git a/edvart/report_sections/group_analysis.py b/edvart/report_sections/group_analysis.py index a751610..7ad113e 100644 --- a/edvart/report_sections/group_analysis.py +++ b/edvart/report_sections/group_analysis.py @@ -640,7 +640,6 @@ def overlaid_histograms( vertical_spacing=0.02, ) - 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])