From 031b5d5f42a35d6306c8c192032f2741d3cfd4f6 Mon Sep 17 00:00:00 2001 From: James Gaboardi Date: Tue, 10 Dec 2024 12:33:05 -0500 Subject: [PATCH] small DRY in artifacts.nx_gx() --- neatnet/artifacts.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/neatnet/artifacts.py b/neatnet/artifacts.py index 7309a4e..6a190a6 100644 --- a/neatnet/artifacts.py +++ b/neatnet/artifacts.py @@ -1073,10 +1073,6 @@ def nx_gx( # correctly pick-up the highest hierarchy and drop all lower if artifact.C > 0: logger.debug("HIGHEST C") - # define mask for E and S strokes - es_mask = edges.coins_group.isin(all_ends.coins_group) - # filter Cs - highest_hierarchy = edges[~es_mask] else: logger.debug("HIGHEST E") singles = set() @@ -1089,12 +1085,14 @@ def nx_gx( ): singles.add(group) visited.append(group) - # filter ends + # re-filter ends all_ends = edges[edges.coins_group.isin(singles)] - # define mask for E and S strokes - es_mask = edges.coins_group.isin(all_ends.coins_group) - # filter Cs - highest_hierarchy = edges[~es_mask] + + # define mask for E and S strokes + es_mask = edges.coins_group.isin(all_ends.coins_group) + + # filter Cs + highest_hierarchy = edges[~es_mask] # get nodes forming the artifact relevant_nodes = nodes.iloc[