Esempio n. 1
0
 def test_csv_format_missing_values(self):
     f = CSVFormat()
     data = Table("../../tests/test9.tab")
     self.assertTrue(
         any([x is "" for instance in data.metas for x in instance]))
     f.write_file(self.CSV_FILE, data)
     new_data = f.read_file(self.CSV_FILE)
     for new_instance, old_instance in zip(new_data, data):
         self.assertEqual(new_instance, old_instance)
Esempio n. 2
0
 def test_csv_format_missing_values(self):
     f = CSVFormat()
     data = Table("../../tests/test9.tab")
     self.assertTrue(any([x is "" for instance in
                          data.metas for x in instance]))
     f.write_file(self.CSV_FILE, data)
     new_data = f.read_file(self.CSV_FILE)
     for new_instance, old_instance in zip(new_data, data):
         self.assertEqual(new_instance, old_instance)
Esempio n. 3
0
 def test_noncontinous_marked_continuous(self):
     file = NamedTemporaryFile("wt", delete=False)
     file.write(noncont_marked_cont)
     file.close()
     with self.assertRaises(ValueError) as cm:
         table = CSVFormat().read_file(file.name)
     self.assertIn('line 5, column 2', cm.exception.args[0])
Esempio n. 4
0
    def test_readwrite_timevariable(self):
        output_csv = StringIO()
        input_csv = StringIO("""\
Date,Feature
time,continuous
,
1920-12-12,1.0
1920-12-13,3.0
1920-12-14,5.5
""")
        for stream in (output_csv, input_csv):
            stream.close = lambda: None  # HACK: Prevent closing of streams

        table = CSVFormat.read_file(input_csv)
        self.assertIsInstance(table.domain['Date'], TimeVariable)
        self.assertEqual(table[0, 'Date'], '1920-12-12')
        # Dates before 1970 are negative
        self.assertTrue(all(inst['Date'] < 0 for inst in table))

        CSVFormat.write_file(output_csv, table)
        self.assertEqual(input_csv.getvalue().splitlines(),
                         output_csv.getvalue().splitlines())
Esempio n. 5
0
    def test_read_timevariable(self):
        example_csv = StringIO("""\
Date,Feature
time,continuous
,
1920-12-12,1
1920-12-13,3
1920-12-14,5.5
""")
        table = CSVFormat.read_file(example_csv)
        self.assertIsInstance(table.domain['Date'], TimeVariable)
        self.assertEqual(table[0, 'Date'], '1920-12-12')
        # Dates before 1970 are negative
        self.assertTrue(all(inst['Date'] < 0 for inst in table))
Esempio n. 6
0
    def read_easy(self, s, name):
        file = NamedTemporaryFile("wt", delete=False)
        filename = file.name
        try:
            file.write(s)
            file.close()
            table = CSVFormat().read_file(filename)

            f1, f2, f3 = table.domain
            self.assertIsInstance(f1, DiscreteVariable)
            self.assertEqual(f1.name, name + "1")
            self.assertIsInstance(f2, ContinuousVariable)
            self.assertEqual(f2.name, name + "2")
            self.assertIsInstance(f3, ContinuousVariable)
            self.assertEqual(f3.name, name + "3")
        finally:
            os.remove(filename)