Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle KeyError #23

Merged
merged 1 commit into from
Aug 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,8 @@ def merge(job_dict, merge_dict, cartouche_list):
param merge_dict: A dictionary defining clusters
param cartouche_list: A list of cartouche dictionaries
"""
# Build a list of cartouche wrappers and frames so we don't merge cartouche inner clusters with their frames
# Build a list of cartouche wrappers and frames so we don't merge cartouche
# inner clusters with their frames
cartouche_clusters = []
for c in cartouche_list:
cartouche_clusters = cartouche_clusters + c['wrapper']
Expand All @@ -441,18 +442,24 @@ def merge(job_dict, merge_dict, cartouche_list):
for outer in merge_dict:
if outer not in cartouche_clusters:
for inner in merge_dict[outer]:
# We may have already processed our raw clusters so want to avoid a key error
# We may have already processed our raw clusters so want to
# avoid a key error
if outer in job_dict[
'clusters_processed'] and inner in job_dict[
'clusters_processed']:
# Merge the 2 clusters and label with the name of the outer cluster then delete the inner cluster
# Merge the 2 clusters and label with the name of the outer
# cluster then delete the inner cluster
job_dict['clusters_processed'][outer] = merge_clusters(
job_dict['clusters_processed'][inner],
job_dict['clusters_processed'][outer])
pop_list.append(inner)
# Remove the clusters that have been merged
for inner in pop_list:
job_dict['clusters_processed'].pop(inner)
try:
job_dict['clusters_processed'].pop(inner)
except KeyError as e:
logging.info('The value inner may have already popped.')
logging.error(e)


def merge_clusters(inner_cluster, outer_cluster):
Expand Down