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


Python array.BlockIndex類代碼示例

本文整理匯總了Python中pandas.sparse.array.BlockIndex的典型用法代碼示例。如果您正苦於以下問題:Python BlockIndex類的具體用法?Python BlockIndex怎麽用?Python BlockIndex使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了BlockIndex類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _check_case

        def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
            xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
            yindex = BlockIndex(TEST_LENGTH, yloc, ylen)

            xdindex = xindex.to_int_index()
            ydindex = yindex.to_int_index()

            x = np.arange(xindex.npoints) * 10. + 1
            y = np.arange(yindex.npoints) * 100. + 1

            xfill = 0
            yfill = 2

            result_block_vals, rb_index, bfill = sparse_op(x, xindex, xfill, y,
                                                           yindex, yfill)
            result_int_vals, ri_index, ifill = sparse_op(x, xdindex, xfill, y,
                                                         ydindex, yfill)

            self.assertTrue(rb_index.to_int_index().equals(ri_index))
            tm.assert_numpy_array_equal(result_block_vals, result_int_vals)
            self.assertEqual(bfill, ifill)

            # check versus Series...
            xseries = Series(x, xdindex.indices)
            xseries = xseries.reindex(np.arange(TEST_LENGTH)).fillna(xfill)

            yseries = Series(y, ydindex.indices)
            yseries = yseries.reindex(np.arange(TEST_LENGTH)).fillna(yfill)

            series_result = python_op(xseries, yseries)
            series_result = series_result.reindex(ri_index.indices)

            tm.assert_numpy_array_equal(result_block_vals,
                                        series_result.values)
            tm.assert_numpy_array_equal(result_int_vals, series_result.values)
開發者ID:llllllllll,項目名稱:pandas,代碼行數:35,代碼來源:test_libsparse.py

示例2: test_to_int_index

    def test_to_int_index(self):
        locs = [0, 10]
        lengths = [4, 6]
        exp_inds = [0, 1, 2, 3, 10, 11, 12, 13, 14, 15]

        block = BlockIndex(20, locs, lengths)
        dense = block.to_int_index()

        assert_equal(dense.indices, exp_inds)
開發者ID:Casyfill,項目名稱:Capstone_dashboard,代碼行數:9,代碼來源:test_libsparse.py

示例3: test_to_int_index

    def test_to_int_index(self):
        locs = [0, 10]
        lengths = [4, 6]
        exp_inds = [0, 1, 2, 3, 10, 11, 12, 13, 14, 15]

        block = BlockIndex(20, locs, lengths)
        dense = block.to_int_index()

        tm.assert_numpy_array_equal(dense.indices,
                                    np.array(exp_inds, dtype=np.int32))
開發者ID:llllllllll,項目名稱:pandas,代碼行數:10,代碼來源:test_libsparse.py

示例4: _check_case

        def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
            xindex = BlockIndex(TEST_LENGTH, xloc, xlen)
            yindex = BlockIndex(TEST_LENGTH, yloc, ylen)
            bresult = xindex.make_union(yindex)
            assert (isinstance(bresult, BlockIndex))
            assert_equal(bresult.blocs, eloc)
            assert_equal(bresult.blengths, elen)

            ixindex = xindex.to_int_index()
            iyindex = yindex.to_int_index()
            iresult = ixindex.make_union(iyindex)
            assert (isinstance(iresult, IntIndex))
            assert_equal(iresult.indices, bresult.to_int_index().indices)
開發者ID:Casyfill,項目名稱:Capstone_dashboard,代碼行數:13,代碼來源:test_libsparse.py

示例5: test_lookup_basics

    def test_lookup_basics(self):
        def _check(index):
            assert (index.lookup(0) == -1)
            assert (index.lookup(5) == 0)
            assert (index.lookup(7) == 2)
            assert (index.lookup(8) == -1)
            assert (index.lookup(9) == -1)
            assert (index.lookup(10) == -1)
            assert (index.lookup(11) == -1)
            assert (index.lookup(12) == 3)
            assert (index.lookup(17) == 8)
            assert (index.lookup(18) == -1)

        bindex = BlockIndex(20, [5, 12], [3, 6])
        iindex = bindex.to_int_index()

        _check(bindex)
        _check(iindex)
開發者ID:llllllllll,項目名稱:pandas,代碼行數:18,代碼來源:test_libsparse.py

示例6: test_to_block_index

 def test_to_block_index(self):
     index = BlockIndex(10, [0, 5], [4, 5])
     self.assertIs(index.to_block_index(), index)
開發者ID:llllllllll,項目名稱:pandas,代碼行數:3,代碼來源:test_libsparse.py

示例7: test_equals

    def test_equals(self):
        index = BlockIndex(10, [0, 4], [2, 5])

        self.assertTrue(index.equals(index))
        self.assertFalse(index.equals(BlockIndex(10, [0, 4], [2, 6])))
開發者ID:llllllllll,項目名稱:pandas,代碼行數:5,代碼來源:test_libsparse.py


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