[py3] use six.iteritems instead of dict.iteritems
authorSamuel Trégouët <samuel.tregouet@logilab.fr>
Wed, 27 Jun 2018 17:28:36 +0200
changeset 529 92191030ab31
parent 528 328718ff629e
child 530 c22b96297291
[py3] use six.iteritems instead of dict.iteritems
nazca/rl/aligner.py
nazca/rl/blocking.py
nazca/utils/dataio.py
--- a/nazca/rl/aligner.py	Wed Jun 27 16:55:15 2018 +0200
+++ b/nazca/rl/aligner.py	Wed Jun 27 17:28:36 2018 +0200
@@ -18,6 +18,8 @@
 import logging
 from collections import defaultdict
 
+from six import iteritems
+
 from scipy import zeros
 from scipy.sparse import lil_matrix
 
@@ -126,7 +128,7 @@
         matched = self.threshold_matched(mat)
         # Reapply matched to global indexes
         new_matched = {}
-        for k, values in matched.iteritems():
+        for k, values in iteritems(matched):
             new_matched[ref_indexes[k]] = [(target_indexes[i], d) for i, d in values]
         return mat, new_matched
 
@@ -152,7 +154,7 @@
             target_index = [r[0] for r in targetblock]
             self.nb_comparisons += len(ref_index)*len(target_index)
             _, matched = self._get_match(refset, targetset, ref_index, target_index)
-            for k, values in matched.iteritems():
+            for k, values in iteritems(matched):
                 subdict = global_matched.setdefault(k, set())
                 for v, d in values:
                     subdict.add((v, d))
--- a/nazca/rl/blocking.py	Wed Jun 27 16:55:15 2018 +0200
+++ b/nazca/rl/blocking.py	Wed Jun 27 17:28:36 2018 +0200
@@ -30,6 +30,8 @@
 from functools import partial
 import warnings
 
+from six import iteritems
+
 from scipy.spatial import KDTree
 
 from nazca.utils.minhashing import Minlsh
@@ -233,7 +235,7 @@
                           and containts the indexes of the record in the
                           corresponding dataset.
         """
-        for key, block1 in self.reference_index.iteritems():
+        for key, block1 in iteritems(self.reference_index):
             block2 = self.target_index.get(key)
             if block1 and block2:
                 yield (block1, block2)
@@ -287,7 +289,7 @@
     def _iter_dict(self, ref_cur_dict, target_cur_dict):
         """ Iterative function used to create blocks from dicts
         """
-        for key, sub_dict in ref_cur_dict.iteritems():
+        for key, sub_dict in iteritems(ref_cur_dict):
             if key in target_cur_dict:
                 if isinstance(sub_dict, dict):
                     # There is another dict layer
--- a/nazca/utils/dataio.py	Wed Jun 27 16:55:15 2018 +0200
+++ b/nazca/utils/dataio.py	Wed Jun 27 17:28:36 2018 +0200
@@ -22,6 +22,8 @@
 import csv
 import urllib
 
+from six import iteritems
+
 from lxml import etree
 
 try:
@@ -161,7 +163,7 @@
     results = rawresults["results"]["bindings"]
     data_lang = {}
     for row in results:
-        for k, v in row.iteritems():
+        for k, v in iteritems(row):
             if v['type'] == 'uri':
                 # Uri, keep it in a set
                 data.setdefault(k, set()).add(v['value'])
@@ -172,7 +174,7 @@
                 # Literal - Use lang
                 data_lang.setdefault(k, []).append((v['value'], v.get('xml:lang')))
     keyfunc = lambda x: lang_order.index(x[1]) if x[1] in lang_order else len(lang_order)
-    data.update(dict([(k, sorted(v, key=keyfunc)[0][0]) for k, v in data_lang.iteritems()]))
+    data.update(dict([(k, sorted(v, key=keyfunc)[0][0]) for k, v in iteritems(data_lang)]))
     return data