[Scipy-svn] r6781 - in trunk/scipy/io/arff: . tests

scipy-svn@scip... scipy-svn@scip...
Sat Sep 11 23:28:18 CDT 2010


Author: warren.weckesser
Date: 2010-09-11 23:28:18 -0500 (Sat, 11 Sep 2010)
New Revision: 6781

Modified:
   trunk/scipy/io/arff/arffread.py
   trunk/scipy/io/arff/tests/test_data.py
Log:
BUG: io.arff: Ensure that the order of the types returned by MetaData.types() matches the order of the names returned by MetaData.names(). Fixes #966.

Modified: trunk/scipy/io/arff/arffread.py
===================================================================
--- trunk/scipy/io/arff/arffread.py	2010-09-12 03:14:32 UTC (rev 6780)
+++ trunk/scipy/io/arff/arffread.py	2010-09-12 04:28:18 UTC (rev 6781)
@@ -450,7 +450,8 @@
 
     def types(self):
         """Return the list of attribute types."""
-        return [v[0] for v in self._attributes.values()]
+        attr_types = [self._attributes[name][0] for name in self._attrnames]
+        return attr_types
 
 
 def loadarff(filename):

Modified: trunk/scipy/io/arff/tests/test_data.py
===================================================================
--- trunk/scipy/io/arff/tests/test_data.py	2010-09-12 03:14:32 UTC (rev 6780)
+++ trunk/scipy/io/arff/tests/test_data.py	2010-09-12 04:28:18 UTC (rev 6781)
@@ -1,14 +1,16 @@
 #!/usr/bin/env python
 """Tests for parsing full arff files."""
+
 import os
 from os.path import join as pjoin
 
 import numpy as np
 
-from numpy.testing import TestCase, assert_array_almost_equal
+from numpy.testing import TestCase, assert_array_almost_equal, assert_equal
 
 from scipy.io.arff.arffread import loadarff
 
+
 data_path = pjoin(os.path.dirname(__file__), 'data')
 
 test4 = pjoin(data_path, 'test4.arff')
@@ -16,6 +18,7 @@
 expect4_data = [(0.1, 0.2, 0.3, 0.4, 'class1'),
         (-0.1, -0.2, -0.3, -0.4, 'class2'),
         (1, 2, 3, 4, 'class3')]
+expected_types = ['numeric', 'numeric', 'numeric', 'numeric', 'nominal']
 
 missing = pjoin(data_path, 'missing.arff')
 expect_missing_raw = np.array([[1, 5], [2, 4], [np.nan, np.nan]])
@@ -23,6 +26,7 @@
 expect_missing['yop'] = expect_missing_raw[:, 0]
 expect_missing['yap'] = expect_missing_raw[:, 1]
 
+
 class DataTest(TestCase):
     def test1(self):
         """Parsing trivial file with nothing."""
@@ -37,12 +41,11 @@
         for i in range(len(data)):
             for j in range(4):
                 assert_array_almost_equal(expect4_data[i][j], data[i][j])
+        assert_equal(meta.types(), expected_types)
 
+
 class MissingDataTest(TestCase):
     def test_missing(self):
         data, meta = loadarff(missing)
         for i in ['yop', 'yap']:
             assert_array_almost_equal(data[i], expect_missing[i])
-
-
-



More information about the Scipy-svn mailing list