From c0baa2df98c9377547f62ab4c72b4c25c2527bc2 Mon Sep 17 00:00:00 2001 From: BuysDB Date: Wed, 7 Oct 2020 23:15:02 +0200 Subject: [PATCH 1/2] Raise a more descriptive error message by reporting the erroneous box name and available box names. --- statannot/statannot.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/statannot/statannot.py b/statannot/statannot.py index 05e3009..1c560de 100644 --- a/statannot/statannot.py +++ b/statannot/statannot.py @@ -468,10 +468,14 @@ def get_box_data(box_plotter, boxName): # Build the list of box data structure pairs box_struct_pairs = [] for i_box_pair, (box1, box2) in enumerate(box_pairs): + valid = box1 in box_names and box2 in box_names if not valid: - raise ValueError("box_pairs contains an invalid box pair.") - pass + if not box1 in box_names: + raise ValueError(f"box_pairs contains an invalid box pair, expected {box1} in {box_names}") + else: + raise ValueError(f"box_pairs contains an invalid box pair, expected {box2} in {box_names}") + # i_box_pair will keep track of the original order of the box pairs. box_struct1 = dict(box_structs_dic[box1], i_box_pair=i_box_pair) box_struct2 = dict(box_structs_dic[box2], i_box_pair=i_box_pair) From 299e74d10655f15794db390c1f4343c803f75f4b Mon Sep 17 00:00:00 2001 From: BuysDB Date: Wed, 7 Oct 2020 23:23:04 +0200 Subject: [PATCH 2/2] Reduced linecount --- statannot/statannot.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/statannot/statannot.py b/statannot/statannot.py index 1c560de..2c618f0 100644 --- a/statannot/statannot.py +++ b/statannot/statannot.py @@ -469,12 +469,8 @@ def get_box_data(box_plotter, boxName): box_struct_pairs = [] for i_box_pair, (box1, box2) in enumerate(box_pairs): - valid = box1 in box_names and box2 in box_names - if not valid: - if not box1 in box_names: - raise ValueError(f"box_pairs contains an invalid box pair, expected {box1} in {box_names}") - else: - raise ValueError(f"box_pairs contains an invalid box pair, expected {box2} in {box_names}") + if box1 not in box_names or box2 not in box_names: + raise ValueError(f"box_pairs contains an invalid box pair, expected {box1 if not box1 in box_names else box2} in {box_names}") # i_box_pair will keep track of the original order of the box pairs. box_struct1 = dict(box_structs_dic[box1], i_box_pair=i_box_pair)