本文整理汇总了Python中dazzle.core.table.Table.append方法的典型用法代码示例。如果您正苦于以下问题:Python Table.append方法的具体用法?Python Table.append怎么用?Python Table.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dazzle.core.table.Table
的用法示例。
在下文中一共展示了Table.append方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestColumn
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import append [as 别名]
class TestColumn(unittest.TestCase):
def setUp(self):
self.a = [6, 4, 7, 4, 6, 9]
self.test_dir = os.path.join("/temp", "dazzle-test")
ds = DataSet(self.test_dir, force_create=True)
self.t = Table("t", ds, [("a", np.array([1, 3], dtype=np.int8)), ("x", np.array([2, 4], dtype=np.float))], force_create=True)
self.ca = self.t.get_column("a")
@raises(DazzleError)
def test_data_dir01(self):
"""no table associated"""
print(LiteralColumn("a", np.array([], np.int)).data_dir)
def test_data_dir02(self):
self.assertEqual(self.ca.data_dir, os.path.join(self.test_dir, "t", "a"))
@raises(DazzleError)
def test_carray01(self):
"""no table associated"""
print(LiteralColumn("a", np.array([], np.int)).carray)
def test_carray02(self):
assert_array_equal(self.ca.carray[:], [1, 3])
@raises(DazzleError)
def test_init01(self):
LiteralColumn("", [])
@raises(DazzleError)
def test_init02(self):
LiteralColumn("1a", [])
@raises(DazzleError)
def test_init03(self):
LiteralColumn("_a", [])
@raises(DazzleError)
def test_init04(self):
LiteralColumn("a", "XX")
@raises(DazzleError)
def test_init05(self):
LiteralColumn("a", self)
def test_init06(self):
assert_array_equal(self.ca.carray[:], [1, 3])
def test_len01(self):
self.assertEqual(len(self.ca), 2)
def test_position01(self):
self.t.append({'a': self.a, 'x': self.a})
self.assertEqual(self.ca.position, 0)
def test_position02(self):
self.t.append({'a': self.a, 'x': self.a})
self.assertEqual(self.t.get_column("x").position, 1)
def test_getitem01(self):
self.assertEqual(self.ca[0], 1)
def test_getitem02(self):
self.assertEqual(self.ca[1], 3)
@raises(IndexError)
def test_getitem03(self):
self.t.append({'a': self.a, 'x': self.a})
_ = self.ca[10]
def test_getitem04(self):
self.t.append({'a': self.a, 'x': self.a})
assert_array_equal(self.ca[:], self.ca.carray[:])
def test_getitem05(self):
self.t.append({'a': self.a, 'x': self.a})
assert_array_equal(self.ca[0:5], [1, 3, 6, 4, 7])
def test_setitem01(self):
self.ca[0] = 2
self.assertEqual(self.ca[0], 2)
assert_array_equal(self.ca.carray[:], [2, 3])
def test_append01(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.append(self.a)
assert_array_equal(self.ca.carray[:], [1, 3, 6, 4, 7, 4, 6, 9, 6, 4, 7, 4, 6, 9])
@raises(DazzleError)
def test_rename01(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.rename("")
@raises(DazzleError)
def test_rename02(self):
self.t.append({'a': self.a, 'x': self.a})
self.ca.rename("x")
def test_rename03(self):
self.ca.rename("b")
#.........这里部分代码省略.........
示例2: TestTable
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import append [as 别名]
#.........这里部分代码省略.........
def test_from_csv03(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), verbose=False)
def test_from_csv04(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), delimiter='\t',
usecols=['CategoryID', 'ParentCategoryID'], verbose=False)
self.assertEqual(len(cat.ctable), 68)
self.assertEqual(len(cat.columns), 2)
def test_from_dataframe01(self):
df = pd.DataFrame({'a': [1,2], 'b': [3., 4.]})
v = Table.from_dataframe("v", self.ds, df)
self.assertEqual(len(v.ctable), 2)
def test_get_column01(self):
self.assertTrue(self.t.get_column("x") is None)
def test_get_column02(self):
self.assertEqual(self.t.get_column("a").name, "a")
@raises(ValueError)
def test_remove_column01(self):
self.t.remove_column("x")
def test_remove_column02(self):
self.t.remove_column("a")
self.assertTrue(self.t.get_column("a") is None)
self.assertEqual(self.t.columns[0], self.t.get_column("b"))
self.assertEqual(self.t.ctable.names[0], "b")
def test_to_dataframe01(self):
self.assertEqual(len(self.u.to_dataframe()), 2)
def test_append01(self):
self.t.append({'a': [1,2], 'b': [3., 4.]})
self.assert_table_content(self.t, {
'len': 2,
'columns': [('a', {'content': [1,2]}), ('b', {'content': [3., 4.]})]})
def test_append02(self):
self.t.append({'b': [3., 4.], 'a': [1,2]})
self.assert_table_content(self.t, {
'len': 2,
'columns': [('a', {'content': [1,2]}), ('b', {'content': [3., 4.]})]})
def test_append03(self):
self.t.append({'a': [5.4, 2], 'b': [3., 4.]})
@raises(ValueError)
def test_append04(self):
self.t.append({'a': ["bla", 2], 'b': [3., 4.]})
@raises(ValueError)
def test_append05(self):
self.t.append({'a': [], 'b': [3., 4.]})
@raises(ValueError)
def test_append06(self):
self.t.append({'a': []})
@raises(ValueError)
def test_append05(self):
self.t.append([[], [3., 4.]])
def test_get_item01(self):
self.assertEqual(self.u[0]['a'], 1)