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


Python pyarrow.from_pylist函数代码示例

本文整理汇总了Python中pyarrow.from_pylist函数的典型用法代码示例。如果您正苦于以下问题:Python from_pylist函数的具体用法?Python from_pylist怎么用?Python from_pylist使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_recordbatch_slice

def test_recordbatch_slice():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10])
    ]
    names = ['c0', 'c1']

    batch = pa.RecordBatch.from_arrays(data, names)

    sliced = batch.slice(2)

    assert sliced.num_rows == 3

    expected = pa.RecordBatch.from_arrays(
        [x.slice(2) for x in data], names)
    assert sliced.equals(expected)

    sliced2 = batch.slice(2, 2)
    expected2 = pa.RecordBatch.from_arrays(
        [x.slice(2, 2) for x in data], names)
    assert sliced2.equals(expected2)

    # 0 offset
    assert batch.slice(0).equals(batch)

    # Slice past end of array
    assert len(batch.slice(len(batch))) == 0

    with pytest.raises(IndexError):
        batch.slice(-1)
开发者ID:julienledem,项目名称:arrow,代码行数:30,代码来源:test_table.py

示例2: test_concat_tables

def test_concat_tables():
    data = [
        list(range(5)),
        [-10., -5., 0., 5., 10.]
    ]
    data2 = [
        list(range(5, 10)),
        [1., 2., 3., 4., 5.]
    ]

    t1 = pa.Table.from_arrays([pa.from_pylist(x) for x in data],
                              names=('a', 'b'), name='table_name')
    t2 = pa.Table.from_arrays([pa.from_pylist(x) for x in data2],
                              names=('a', 'b'), name='table_name')

    result = pa.concat_tables([t1, t2], output_name='foo')
    assert result.name == 'foo'
    assert len(result) == 10

    expected = pa.Table.from_arrays([pa.from_pylist(x + y)
                                     for x, y in zip(data, data2)],
                                    names=('a', 'b'),
                                    name='foo')

    assert result.equals(expected)
开发者ID:julienledem,项目名称:arrow,代码行数:25,代码来源:test_table.py

示例3: test_to_pandas_zero_copy

def test_to_pandas_zero_copy():
    import gc

    arr = pyarrow.from_pylist(range(10))

    for i in range(10):
        np_arr = arr.to_pandas()
        assert sys.getrefcount(np_arr) == 2
        np_arr = None  # noqa

    assert sys.getrefcount(arr) == 2

    for i in range(10):
        arr = pyarrow.from_pylist(range(10))
        np_arr = arr.to_pandas()
        arr = None
        gc.collect()

        # Ensure base is still valid

        # Because of py.test's assert inspection magic, if you put getrefcount
        # on the line being examined, it will be 1 higher than you expect
        base_refcount = sys.getrefcount(np_arr.base)
        assert base_refcount == 2
        np_arr.sum()
开发者ID:julienledem,项目名称:arrow,代码行数:25,代码来源:test_array.py

示例4: test_array_slice

def test_array_slice():
    arr = pyarrow.from_pylist(range(10))

    sliced = arr.slice(2)
    expected = pyarrow.from_pylist(range(2, 10))
    assert sliced.equals(expected)

    sliced2 = arr.slice(2, 4)
    expected2 = pyarrow.from_pylist(range(2, 6))
    assert sliced2.equals(expected2)

    # 0 offset
    assert arr.slice(0).equals(arr)

    # Slice past end of array
    assert len(arr.slice(len(arr))) == 0

    with pytest.raises(IndexError):
        arr.slice(-1)

    # Test slice notation
    assert arr[2:].equals(arr.slice(2))

    assert arr[2:5].equals(arr.slice(2, 3))

    assert arr[-5:].equals(arr.slice(len(arr) - 5))

    with pytest.raises(IndexError):
        arr[::-1]

    with pytest.raises(IndexError):
        arr[::2]
开发者ID:julienledem,项目名称:arrow,代码行数:32,代码来源:test_array.py

示例5: test_garbage_collection

    def test_garbage_collection(self):
        import gc

        # Force the cyclic garbage collector to run
        gc.collect()

        bytes_before = pyarrow.total_allocated_bytes()
        pyarrow.from_pylist([1, None, 3, None])
        gc.collect()
        assert pyarrow.total_allocated_bytes() == bytes_before
开发者ID:apache,项目名称:arrow,代码行数:10,代码来源:test_convert_builtin.py

示例6: test_recordbatch_basics

def test_recordbatch_basics():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10])
    ]

    batch = pa.RecordBatch.from_arrays(['c0', 'c1'], data)

    assert len(batch) == 5
    assert batch.num_rows == 5
    assert batch.num_columns == len(data)
开发者ID:apache,项目名称:arrow,代码行数:11,代码来源:test_table.py

示例7: test_table_remove_column

def test_table_remove_column():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10]),
        pa.from_pylist(range(5, 10))
    ]
    table = pa.Table.from_arrays(data, names=('a', 'b', 'c'))

    t2 = table.remove_column(0)
    expected = pa.Table.from_arrays(data[1:], names=('b', 'c'))
    assert t2.equals(expected)
开发者ID:StevenMPhillips,项目名称:arrow,代码行数:11,代码来源:test_table.py

示例8: test_recordbatch_basics

def test_recordbatch_basics():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10])
    ]

    batch = pa.RecordBatch.from_arrays(data, ['c0', 'c1'])

    assert len(batch) == 5
    assert batch.num_rows == 5
    assert batch.num_columns == len(data)
    assert batch.to_pydict() == OrderedDict([
        ('c0', [0, 1, 2, 3, 4]),
        ('c1', [-10, -5, 0, 5, 10])
    ])
开发者ID:julienledem,项目名称:arrow,代码行数:15,代码来源:test_table.py

示例9: test_table_basics

def test_table_basics():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10])
    ]
    table = pa.Table.from_arrays(('a', 'b'), data, 'table_name')
    assert table.name == 'table_name'
    assert len(table) == 5
    assert table.num_rows == 5
    assert table.num_columns == 2
    assert table.shape == (5, 2)

    for col in table.itercolumns():
        for chunk in col.data.iterchunks():
            assert chunk is not None
开发者ID:apache,项目名称:arrow,代码行数:15,代码来源:test_table.py

示例10: test_double

 def test_double(self):
     data = [1.5, 1, None, 2.5, None, None]
     arr = pyarrow.from_pylist(data)
     assert len(arr) == 6
     assert arr.null_count == 3
     assert arr.type == pyarrow.double()
     assert arr.to_pylist() == data
开发者ID:apache,项目名称:arrow,代码行数:7,代码来源:test_convert_builtin.py

示例11: test_boolean

 def test_boolean(self):
     expected = [True, None, False, None]
     arr = pyarrow.from_pylist(expected)
     assert len(arr) == 4
     assert arr.null_count == 2
     assert arr.type == pyarrow.bool_()
     assert arr.to_pylist() == expected
开发者ID:apache,项目名称:arrow,代码行数:7,代码来源:test_convert_builtin.py

示例12: test_unicode

 def test_unicode(self):
     data = [u'foo', u'bar', None, u'mañana']
     arr = pyarrow.from_pylist(data)
     assert len(arr) == 4
     assert arr.null_count == 1
     assert arr.type == pyarrow.string()
     assert arr.to_pylist() == data
开发者ID:kiril-me,项目名称:arrow,代码行数:7,代码来源:test_convert_builtin.py

示例13: test_fixed_size_bytes

 def test_fixed_size_bytes(self):
     data = [b'foof', None, b'barb', b'2346']
     arr = pa.from_pylist(data, type=pa.binary(4))
     assert len(arr) == 4
     assert arr.null_count == 1
     assert arr.type == pa.binary(4)
     assert arr.to_pylist() == data
开发者ID:StevenMPhillips,项目名称:arrow,代码行数:7,代码来源:test_convert_builtin.py

示例14: test_table_pandas

def test_table_pandas():
    data = [
        pa.from_pylist(range(5)),
        pa.from_pylist([-10, -5, 0, 5, 10])
    ]
    table = pa.Table.from_arrays(('a', 'b'), data, 'table_name')

    # TODO: Use this part once from_pandas is implemented
    # data = {'a': range(5), 'b': [-10, -5, 0, 5, 10]}
    # df = pd.DataFrame(data)
    # pa.Table.from_pandas(df)

    df = table.to_pandas()
    assert set(df.columns) == set(('a', 'b'))
    assert df.shape == (5, 2)
    assert df.loc[0, 'b'] == -10
开发者ID:apache,项目名称:arrow,代码行数:16,代码来源:test_table.py

示例15: test_unicode

 def test_unicode(self):
     data = [u("foo"), u("bar"), None, u("arrow")]
     arr = pyarrow.from_pylist(data)
     assert len(arr) == 4
     assert arr.null_count == 1
     assert arr.type == pyarrow.string()
     assert arr.to_pylist() == [u("foo"), u("bar"), None, u("arrow")]
开发者ID:apache,项目名称:arrow,代码行数:7,代码来源:test_convert_builtin.py


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