[matrix] "temporal()" may not be defined, depending one dateutil
authorVincent Michel <vincent.michel@logilab.fr>
Thu, 25 Apr 2013 16:05:11 +0200
changeset 260 26e515174f63
parent 259 09b8b1c342e1
child 261 60f374787ab8
[matrix] "temporal()" may not be defined, depending one dateutil
matrix.py
test/test_alignment.py
--- a/matrix.py	Wed Apr 24 10:16:33 2013 +0200
+++ b/matrix.py	Thu Apr 25 16:05:11 2013 +0200
@@ -22,8 +22,13 @@
 import nazca.distances as ds
 
 METRICS = {'euclidean': ds.euclidean, 'levenshtein': ds.levenshtein,
-           'soundex': ds.soundex, 'jaccard': ds.jaccard,
-           'temporal': ds.temporal, 'geographical': ds.geographical}
+           'soundex': ds.soundex, 'jaccard': ds.jaccard, 'geographical': ds.geographical}
+
+try:
+    from nazca.distances import temporal
+    METRICS['temporal'] = temporal
+except ImportError:
+    pass
 
 
 def pdist(X, metric='euclidean', matrix_normalized=True, metric_params=None):
--- a/test/test_alignment.py	Wed Apr 24 10:16:33 2013 +0200
+++ b/test/test_alignment.py	Thu Apr 25 16:05:11 2013 +0200
@@ -29,8 +29,7 @@
 from dateutil import parser as dateparser
 
 from nazca.distances import (levenshtein, soundex, soundexcode,   \
-                                 jaccard, temporal, euclidean,        \
-                                 geographical)
+                             jaccard, euclidean, geographical)
 from nazca.normalize import (lunormalize, loadlemmas, lemmatized, \
                                  roundstr, rgxformat, tokenize, simplify)
 import nazca.matrix as am
@@ -107,7 +106,10 @@
     def test_temporal(self):
         #Test the distance between two dates. The distance can be given in
         #``days``, ``months`` or ``years``
-
+        try:
+            from nazca.distances import temporal
+        except ImportError:
+            return
         self.assertEqual(temporal('14 aout 1991', '14/08/1991'), 0)
         self.assertEqual(temporal('14 aout 1991', '08/14/1991'), 0)
         self.assertEqual(temporal('14 aout 1991', '08/15/1992'), 367)