当前位置: 首页>>代码示例>>Python>>正文


Python Table.save方法代码示例

本文整理汇总了Python中Orange.data.Table.save方法的典型用法代码示例。如果您正苦于以下问题:Python Table.save方法的具体用法?Python Table.save怎么用?Python Table.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Orange.data.Table的用法示例。


在下文中一共展示了Table.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_attributes_saving

# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import save [as 别名]
 def test_attributes_saving(self):
     tempdir = tempfile.mkdtemp()
     table = Table("iris")
     self.assertEqual(table.attributes, {})
     table.attributes[1] = "test"
     table.save(path.join(tempdir, "out.tab"))
     table = Table(path.join(tempdir, "out.tab"))
     self.assertEqual(table.attributes[1], "test")
     shutil.rmtree(tempdir)
开发者ID:675801717,项目名称:orange3,代码行数:11,代码来源:test_tab_reader.py

示例2: test_attributes_saving_as_txt

# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import save [as 别名]
 def test_attributes_saving_as_txt(self):
     tempdir = tempfile.mkdtemp()
     table = Table("titanic")
     table.attributes = OrderedDict()
     table.attributes["a"] = "aa"
     table.attributes["b"] = "bb"
     table.save(path.join(tempdir, "out.tab"))
     table = Table(path.join(tempdir, "out.tab"))
     self.assertIsInstance(table.attributes, OrderedDict)
     self.assertEqual(table.attributes["a"], "aa")
     self.assertEqual(table.attributes["b"], "bb")
     shutil.rmtree(tempdir)
开发者ID:RachitKansal,项目名称:orange3,代码行数:14,代码来源:test_tab_reader.py

示例3: test_file_not_found

# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import save [as 别名]
    def test_file_not_found(self):
        # Create a dummy file
        file_name = "test_owfile_data.tab"
        domainA = Domain([DiscreteVariable("d1", values=("a", "b"))],
                         DiscreteVariable("c1", values=("aaa", "bbb")))
        dataA = Table(domainA, np.array([[0], [1], [0], [np.nan]]),
                      np.array([0, 1, 0, 1]))
        dataA.save(file_name)

        # Open the file with the widget
        self.open_dataset(file_name)
        self.assertEqual(self.get_output(self.widget.Outputs.data).domain, dataA.domain)

        # Delete the file and try to reload it
        remove(file_name)
        self.widget.load_data()
        self.assertEqual(file_name, path.basename(self.widget.last_path()))
        self.assertTrue(self.widget.Error.file_not_found.is_shown())
        self.assertIsNone(self.get_output(self.widget.Outputs.data))
        self.assertEqual(self.widget.info.text(), "No data.")

        # Open a sample dataset
        self.open_dataset("iris")
        self.assertFalse(self.widget.Error.file_not_found.is_shown())
开发者ID:nikicc,项目名称:orange3,代码行数:26,代码来源:test_owfile.py

示例4: TestTabReader

# 需要导入模块: from Orange.data import Table [as 别名]
# 或者: from Orange.data.Table import save [as 别名]
class TestTabReader(unittest.TestCase):

    def setUp(self):
        DiscreteVariable._clear_cache()
        self.data = Table([[1, 2, 3]])

    def test_read_easy(self):
        simplefile = """\
        Feature 1\tFeature 2\tClass 1\tClass 42
        d        \tM F      \td      \td
                 \t         \tclass  \tclass
        1.0      \tM        \t5      \trich
                 \tF        \t7      \tpoor
        2.0      \tM        \t4      \t
        """

        file = io.StringIO(simplefile)
        table = read_tab_file(file)

        f1, f2, c1, c2 = table.domain.variables
        self.assertIsInstance(f1, DiscreteVariable)
        self.assertEqual(f1.name, "Feature 1")
        self.assertIsInstance(f2, DiscreteVariable)
        self.assertEqual(f2.name, "Feature 2")
        self.assertIsInstance(c1, DiscreteVariable)
        self.assertEqual(c1.name, "Class 1")
        self.assertIsInstance(c2, DiscreteVariable)
        self.assertEqual(c2.name, "Class 42")

        np.testing.assert_almost_equal(table.X, np.array([[0, 0], [np.nan, 1], [1, 0]]))
        np.testing.assert_almost_equal(table.Y, np.array([[1, 1], [2, 0], [0, np.nan]]))

    def test_read_save_quoted(self):
        quoted = '''\
        S\tA
        s\td
        m\t
        """a"""\ti
        """b"""\tj
        """c\td"""\tk
        '''
        expected = ['"a"', '"b"', '"c\td"']
        f = io.StringIO(quoted)
        table = read_tab_file(f)
        self.assertSequenceEqual(table.metas[:, 0].tolist(), expected)

        f = io.StringIO()
        f.close = lambda: None
        TabReader.write_file(f, table)
        saved = f.getvalue()
        table1 = read_tab_file(io.StringIO(saved))
        self.assertSequenceEqual(table1.metas[:, 0].tolist(), expected)

    def test_read_and_save_attributes(self):
        samplefile = """\
        Feature 1\tFeature 2\tClass 1\tClass 42
        d        \tM F      \td      \td
                 \ta=1 b=2 \tclass x=a\\ longer\\ string \tclass
        1.0      \tM        \t5      \trich
        """
        file = io.StringIO(samplefile)
        table = read_tab_file(file)

        f1, f2, c1, c2 = table.domain.variables
        self.assertIsInstance(f2, DiscreteVariable)
        self.assertEqual(f2.name, "Feature 2")
        self.assertEqual(f2.attributes, {'a': 1, 'b': 2})
        self.assertIn(c1, table.domain.class_vars)
        self.assertIsInstance(c1, DiscreteVariable)
        self.assertEqual(c1.name, "Class 1")
        self.assertEqual(c1.attributes, {'x': 'a longer string'})
        outf = io.StringIO()
        outf.close = lambda: None
        TabReader.write_file(outf, table)
        saved = outf.getvalue()

        file = io.StringIO(saved)
        table = read_tab_file(file)

        f1, f2, c1, c2 = table.domain.variables
        self.assertIsInstance(f2, DiscreteVariable)
        self.assertEqual(f2.name, "Feature 2")
        self.assertEqual(f2.attributes, {'a': 1, 'b': 2})
        self.assertIn(c1, table.domain.class_vars)
        self.assertIsInstance(c1, DiscreteVariable)
        self.assertEqual(c1.name, "Class 1")
        self.assertEqual(c1.attributes, {'x': 'a longer string'})

        path = "/path/to/somewhere"
        c1.attributes["path"] = path
        outf = io.StringIO()
        outf.close = lambda: None
        TabReader.write_file(outf, table)
        outf.seek(0)

        table = read_tab_file(outf)
        f1, f2, c1, c2 = table.domain.variables
        self.assertEqual(c1.attributes["path"], path)

    def test_read_data_oneline_header(self):
#.........这里部分代码省略.........
开发者ID:PrimozGodec,项目名称:orange3,代码行数:103,代码来源:test_tab_reader.py


注:本文中的Orange.data.Table.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。