本文整理汇总了Python中dazzle.core.table.Table.tail方法的典型用法代码示例。如果您正苦于以下问题:Python Table.tail方法的具体用法?Python Table.tail怎么用?Python Table.tail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dazzle.core.table.Table
的用法示例。
在下文中一共展示了Table.tail方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestTable
# 需要导入模块: from dazzle.core.table import Table [as 别名]
# 或者: from dazzle.core.table.Table import tail [as 别名]
#.........这里部分代码省略.........
def test_str01(self):
s = \
"u(a: int32, b: float64)" \
"2 row(s) - compressed: 2.00 MB - comp. ratio: 0.00" \
"+---+-------+" \
"| a | b |" \
"+---+-------+" \
"| 1 | 1.100 |" \
"| 2 | 2.200 |" \
"+---+-------+"
self.assert_string_equal(self.u.__str__(), s)
def test_str02(self):
s = \
"u(a: int32, b: float64)" \
"2 row(s) - compressed: 2.00 MB - comp. ratio: 0.00" \
"+---+-------+" \
"| a | b |" \
"+---+-------+" \
"| 1 | 1.100 |" \
"| 2 | 2.200 |" \
"+---+-------+"
self.assert_string_equal(self.u.__str__(head=20), s)
def test_str03(self):
s = \
"u(a: int32, b: float64)" \
"2 row(s) - compressed: 2.00 MB - comp. ratio: 0.00" \
"+---+-----+" \
"| a | b |" \
"+---+-----+" \
"| 1 | 1.1 |" \
"| 2 | 2.2 |" \
"+---+-----+"
self.u.get_column("b").format = "%.1f"
self.assert_string_equal(self.u.__str__(head=20), s)
def test_head01(self):
s = \
"u(a: int32, b: float64)" \
"2 row(s) - compressed: 2.00 MB - comp. ratio: 0.00" \
"+-----+-------+" \
"| a | b |" \
"+-----+-------+" \
"| 1 | 1.100 |" \
"| ... | ... |" \
"+-----+-------+"
self.assert_string_equal(self.u.head(1), s)
def test_tail01(self):
s = \
"u(a: int32, b: float64)" \
"2 row(s) - compressed: 2.00 MB - comp. ratio: 0.00" \
"+-----+-------+" \
"| a | b |" \
"+-----+-------+" \
"| ... | ... |" \
"| 2 | 2.200 |" \
"+-----+-------+"
self.assert_string_equal(self.u.tail(1), s)
def test_rebuild01(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), delimiter='\t',
usecols=['CategoryID', 'ParentCategoryID', 'Level'], verbose=False)
cat.rebuild({"CategoryID": np.int8, "Level": np.int8, "ParentCategoryID": np.int8})
self.assertEqual(len(cat[:]), 69)
self.assertEqual(cat['CategoryID'].dtype, np.int8)
self.assertEqual(cat[0]['CategoryID'], -128) # int8.min
self.assertEqual(cat[0]['Level'], -128) # int8.min
self.assertEqual(cat[0]['ParentCategoryID'], -128) # int8.min
@raises(DazzleError)
def test_rebuild02(self):
cat = Table.from_csv("Category", self.ds, os.path.join(AVITO_DATA_DIR, "Category.tsv"), delimiter='\t',
usecols=['CategoryID', 'ParentCategoryID', 'Level'], verbose=False)
cat.rebuild({"CategoryID": np.uint8, "Level": np.uint8, "ParentCategoryID": np.uint8})
def test_add_join_column(self):
ds = DataSet("/temp/dazzle-test", force_create=True)
t = Table("t", ds, [('a', np.array([10, 2, 3, 5, 4, 7, 1, 8, 6, 9])),
('c', np.array([100, 20, 30, 50, 40, 70, 10, 80, 60, np.nan]))])
a_ref = np.array([1, 5, 4, 5, 6, 4, 1, 1, 9, 7, 8, 4, 5, 5, 2, 2, 8, 5, 4, 20])
u = Table("u", ds, [('a', a_ref), ("y", a_ref * 10)])
u.get_column("a").ref_column = t.get_column("a")
t.rebuild({'a': np.int8, 'c': np.int8})
u.rebuild({'a': np.int8, 'y': np.int16})
u.add_reference_column(u.get_column("a"), t.get_column("a"))
# print(t.head(20))
# print(u.head(30))
u.add_join_column("result", [u.get_column("a_ref"), t.get_column("c")])
#print(u.head(30))
assert np.array_equal(u['result'],
[-128, 10, 50, 40, 50, 60, 40, 10, 10, -128, 70, 80, 40, 50, 50, 20, 20, 80, 50, 40, -128])