You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2017/11/18 21:26:00 UTC
[arrow] branch master updated: ARROW-1575: [Python] Add tests for
pyarrow.column factory function
This is an automated email from the ASF dual-hosted git repository.
wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git
The following commit(s) were added to refs/heads/master by this push:
new 9f9dc5b ARROW-1575: [Python] Add tests for pyarrow.column factory function
9f9dc5b is described below
commit 9f9dc5b7025744458e50713fa460803bf52f5d33
Author: Wes McKinney <we...@twosigma.com>
AuthorDate: Sat Nov 18 16:25:56 2017 -0500
ARROW-1575: [Python] Add tests for pyarrow.column factory function
Author: Wes McKinney <we...@twosigma.com>
Closes #1329 from wesm/ARROW-1575 and squashes the following commits:
d9f14a12 [Wes McKinney] Add tests for pyarrow.column factory function
---
python/pyarrow/table.pxi | 9 +++++
python/pyarrow/tests/test_table.py | 79 ++++++++++++++++++++++----------------
2 files changed, 55 insertions(+), 33 deletions(-)
diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index 1a9d23d..591f329 100644
--- a/python/pyarrow/table.pxi
+++ b/python/pyarrow/table.pxi
@@ -166,6 +166,15 @@ def chunked_array(arrays, type=None):
def column(object field_or_name, arr):
"""
Create Column object from field/string and array-like data
+
+ Parameters
+ ----------
+ field_or_name : string or Field
+ arr : Array, list of Arrays, or ChunkedArray
+
+ Returns
+ -------
+ column : Column
"""
cdef:
Field boxed_field
diff --git a/python/pyarrow/tests/test_table.py b/python/pyarrow/tests/test_table.py
index 4282224..cd05fb8 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -21,42 +21,55 @@ from pandas.util.testing import assert_frame_equal
import pandas as pd
import pytest
-from pyarrow.compat import unittest
import pyarrow as pa
-class TestColumn(unittest.TestCase):
-
- def test_basics(self):
- data = [
- pa.array([-10, -5, 0, 5, 10])
- ]
- table = pa.Table.from_arrays(data, names=['a'])
- column = table.column(0)
- assert column.name == 'a'
- assert column.length() == 5
- assert len(column) == 5
- assert column.shape == (5,)
- assert column.to_pylist() == [-10, -5, 0, 5, 10]
-
- def test_from_array(self):
- arr = pa.array([0, 1, 2, 3, 4])
-
- col1 = pa.Column.from_array('foo', arr)
- col2 = pa.Column.from_array(pa.field('foo', arr.type), arr)
-
- assert col1.equals(col2)
-
- def test_pandas(self):
- data = [
- pa.array([-10, -5, 0, 5, 10])
- ]
- table = pa.Table.from_arrays(data, names=['a'])
- column = table.column(0)
- series = column.to_pandas()
- assert series.name == 'a'
- assert series.shape == (5,)
- assert series.iloc[0] == -10
+def test_column_basics():
+ data = [
+ pa.array([-10, -5, 0, 5, 10])
+ ]
+ table = pa.Table.from_arrays(data, names=['a'])
+ column = table.column(0)
+ assert column.name == 'a'
+ assert column.length() == 5
+ assert len(column) == 5
+ assert column.shape == (5,)
+ assert column.to_pylist() == [-10, -5, 0, 5, 10]
+
+
+def test_column_factory_function():
+ # ARROW-1575
+ arr = pa.array([0, 1, 2, 3, 4])
+ arr2 = pa.array([5, 6, 7, 8])
+
+ col1 = pa.Column.from_array('foo', arr)
+ col2 = pa.Column.from_array(pa.field('foo', arr.type), arr)
+
+ assert col1.equals(col2)
+
+ col3 = pa.column('foo', [arr, arr2])
+ chunked_arr = pa.chunked_array([arr, arr2])
+ col4 = pa.column('foo', chunked_arr)
+ assert col3.equals(col4)
+
+ col5 = pa.column('foo', arr.to_pandas())
+ assert col5.equals(pa.column('foo', arr))
+
+ # Type mismatch
+ with pytest.raises(ValueError):
+ pa.Column.from_array(pa.field('foo', pa.string()), arr)
+
+
+def test_column_to_pandas():
+ data = [
+ pa.array([-10, -5, 0, 5, 10])
+ ]
+ table = pa.Table.from_arrays(data, names=['a'])
+ column = table.column(0)
+ series = column.to_pandas()
+ assert series.name == 'a'
+ assert series.shape == (5,)
+ assert series.iloc[0] == -10
def test_recordbatch_basics():
--
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].