當前位置: 首頁>>代碼示例>>Python>>正文


Python Table.tail方法代碼示例

本文整理匯總了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])
開發者ID:mpage38,項目名稱:dazzle,代碼行數:104,代碼來源:test_table.py


注:本文中的dazzle.core.table.Table.tail方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。