Skip to content

Commit

Permalink
Visualization: Fix legend argument checking for waterfall/parameter…
Browse files Browse the repository at this point in the history
…/history plots (#1139)

- before the fix a `legend_error` would be thrown when the user supplied the legends as a tuple
- Now handles all data types
- raises `TypeError` for single and multiple results
- raises `ValueError` in case of multiple results when lengths of results and legends do not match


Co-authored-by: Dilan Pathirana <dilan.pathirana@uni-bonn.de>
Co-authored-by: Paul Jonas Jost <70631928+PaulJonasJost@users.noreply.github.com>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent 378f705 commit 9b1bbec
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions pypesto/visualize/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def process_result_list(
"""
# check how many results were passed
single_result = False
legend_error = False
legend_type_error = False
if isinstance(results, list):
if len(results) == 1:
single_result = True
Expand All @@ -68,6 +68,10 @@ def process_result_list(
# create list of legends for later handling
if not isinstance(legends, list):
legends = [legends]
try:
str(legends[0])
except TypeError:
legend_type_error = True
else:
# if more than one result is passed, we use one color per result
colors = assign_colors_for_list(len(results), colors)
Expand All @@ -80,18 +84,19 @@ def process_result_list(
legends.append('Result ' + str(i_leg))
else:
# legends were passed by user: check length
if isinstance(legends, list):
try:
if isinstance(legends, str):
legends = [legends]
if len(legends) != len(results):
legend_error = True
else:
legend_error = True

# size of legend list and size of results does not match
if legend_error:
raise ValueError(
'List of results passed and list of labels do '
'not have the same length but should. Stopping.'
)
raise ValueError(
'List of results passed and list of labels do '
'not have the same length.'
)
except TypeError:
legend_type_error = True

if legend_type_error:
raise TypeError("Unexpected legend type.")

return results, colors, legends

Expand Down

0 comments on commit 9b1bbec

Please sign in to comment.