@@ -103,7 +103,7 @@ def __contains__(self, assembly):
103103
104104 def __add__ (self , other ):
105105 if other in self :
106- raise ValueError ("Assemblies contain shared joints." )
106+ raise ArithmeticError ("Assemblies contain shared joints." )
107107
108108 assembly = Assembly (self .data .shape [0 ])
109109 for link in self ._links + other ._links :
@@ -340,6 +340,7 @@ def calibrate(self, train_data_file):
340340 try :
341341 df .drop ("single" , level = "individuals" , axis = 1 , inplace = True )
342342 except KeyError :
343+ # The "single" individual column may be absent in some training datasets; ignore if missing.
343344 pass
344345 n_bpts = len (df .columns .get_level_values ("bodyparts" ).unique ())
345346 if n_bpts == 1 :
@@ -547,11 +548,9 @@ def push_to_stack(i):
547548 d = self .calc_assembly_mahalanobis_dist (assembly , nan_policy = nan_policy )
548549 if d < d_old :
549550 push_to_stack (new_ind )
550- try :
551- _ , _ , link = heapq .heappop (tabu )
552- heapq .heappush (stack , (- link .affinity , next (counter ), link ))
553- except IndexError :
554- pass
551+ if tabu :
552+ _ , _ , link = heapq .heappop (tabu )
553+ heapq .heappush (stack , (- link .affinity , next (counter ), link ))
555554 else :
556555 heapq .heappush (tabu , (d - d_old , next (counter ), best ))
557556 assembly .__dict__ .update (assembly ._dict )
@@ -597,8 +596,8 @@ def build_assemblies(self, links):
597596 self ._fill_assembly (
598597 assembly , lookup , assembled , self .safe_edge , self .nan_policy
599598 )
600- for link in assembly ._links :
601- i , j = link .idx
599+ for assembly_link in assembly ._links :
600+ i , j = assembly_link .idx
602601 lookup [i ].pop (j )
603602 lookup [j ].pop (i )
604603 assembled .update (assembly ._idx )
@@ -666,6 +665,8 @@ def build_assemblies(self, links):
666665 for idx in store [j ]._idx :
667666 store [idx ] = store [i ]
668667 except KeyError :
668+ # Some links may reference indices that were never added to `store`;
669+ # in that case we intentionally skip merging for this link
669670 pass
670671
671672 # Second pass without edge safety
@@ -1086,6 +1087,7 @@ def parse_ground_truth_data_file(h5_file):
10861087 try :
10871088 df .drop ("single" , axis = 1 , level = "individuals" , inplace = True )
10881089 except KeyError :
1090+ # Ignore if the "single" individual column is absent
10891091 pass
10901092 # Cast columns of dtype 'object' to float to avoid TypeError
10911093 # further down in _parse_ground_truth_data.
0 commit comments