[ 
https://issues.apache.org/jira/browse/ARROW-1575?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16258225#comment-16258225
 ] 

ASF GitHub Bot commented on ARROW-1575:
---------------------------------------

wesm closed pull request #1329: ARROW-1575: [Python] Add tests for 
pyarrow.column factory function
URL: https://github.com/apache/arrow/pull/1329
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/python/pyarrow/table.pxi b/python/pyarrow/table.pxi
index 1a9d23db4..591f32975 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 428222466..cd05fb8e1 100644
--- a/python/pyarrow/tests/test_table.py
+++ b/python/pyarrow/tests/test_table.py
@@ -21,42 +21,55 @@
 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():


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> [Python] Add pyarrow.column factory function
> --------------------------------------------
>
>                 Key: ARROW-1575
>                 URL: https://issues.apache.org/jira/browse/ARROW-1575
>             Project: Apache Arrow
>          Issue Type: New Feature
>          Components: Python
>            Reporter: Wes McKinney
>            Assignee: Wes McKinney
>              Labels: pull-request-available
>             Fix For: 0.8.0
>
>
> This would internally call {{Column.from_array}} as appropriate



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)

Reply via email to