[aligner] safety belt to avoid crash on empty sets
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Tue, 28 Nov 2017 18:15:10 +0100
changeset 518 18c42a345591
parent 517 70c3214006c0
child 520 2381069255a2
[aligner] safety belt to avoid crash on empty sets There are several parts in the code that assume that at least refset is not empty (e.g. log_infos() to compute the alignment progress)
rl/aligner.py
--- a/rl/aligner.py	Fri Jul 21 15:29:25 2017 +0200
+++ b/rl/aligner.py	Tue Nov 28 18:15:10 2017 +0100
@@ -166,6 +166,8 @@
     def get_aligned_pairs(self, refset, targetset, unique=True, use_distance=True):
         """ Get the pairs of aligned elements
         """
+        if not refset or not targetset:
+            return
         global_mat, global_matched = self.align(refset, targetset, get_matrix=use_distance)
         for pair in iter_aligned_pairs(refset, targetset, global_mat, global_matched, unique):
             self.pairs_found += 1
@@ -267,6 +269,8 @@
     def get_aligned_pairs(self, refset, targetset, unique=True):
         """ Get the pairs of aligned elements
         """
+        if not refset or not targetset:
+            return
         start_time = time.time()
         ref_index = range(len(refset))
         target_index = range(len(targetset))