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 2019/02/09 21:03:47 UTC

[arrow] branch master updated: ARROW-4370: [Python] Support conversion of List[Bool] to pandas

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 3e841d7  ARROW-4370: [Python] Support conversion of List[Bool] to pandas
3e841d7 is described below

commit 3e841d7f4c4bb6431559f236061d5c0a640d8c04
Author: Uwe L. Korn <uw...@xhochy.com>
AuthorDate: Sat Feb 9 15:03:39 2019 -0600

    ARROW-4370: [Python] Support conversion of List[Bool] to pandas
    
    Author: Uwe L. Korn <uw...@xhochy.com>
    
    Closes #3593 from xhochy/ARROW-4370 and squashes the following commits:
    
    ce6c197ca <Uwe L. Korn> ARROW-4370:  Support conversion of List to pandas
---
 cpp/src/arrow/python/arrow_to_pandas.cc     | 2 ++
 python/pyarrow/tests/test_convert_pandas.py | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/cpp/src/arrow/python/arrow_to_pandas.cc b/cpp/src/arrow/python/arrow_to_pandas.cc
index 8aa0bf7..efc1449 100644
--- a/cpp/src/arrow/python/arrow_to_pandas.cc
+++ b/cpp/src/arrow/python/arrow_to_pandas.cc
@@ -99,6 +99,7 @@ struct WrapBytes<FixedSizeBinaryType> {
 
 static inline bool ListTypeSupported(const DataType& type) {
   switch (type.id()) {
+    case Type::BOOL:
     case Type::UINT8:
     case Type::INT8:
     case Type::UINT16:
@@ -774,6 +775,7 @@ class ObjectBlock : public PandasBlock {
     } else if (type == Type::LIST) {
       auto list_type = std::static_pointer_cast<ListType>(col->type());
       switch (list_type->value_type()->id()) {
+        CONVERTLISTSLIKE_CASE(BooleanType, BOOL)
         CONVERTLISTSLIKE_CASE(UInt8Type, UINT8)
         CONVERTLISTSLIKE_CASE(Int8Type, INT8)
         CONVERTLISTSLIKE_CASE(UInt16Type, UINT16)
diff --git a/python/pyarrow/tests/test_convert_pandas.py b/python/pyarrow/tests/test_convert_pandas.py
index 9bee905..8f2c2eb 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -1589,6 +1589,15 @@ class TestListTypes(object):
         assert parr[2].as_py() is None
         assert parr[3].as_py() == [0]
 
+    def test_column_of_boolean_list(self):
+        # ARROW-4370: Table to pandas conversion fails for list of bool
+        array = pa.array([[True, False], [True]], type=pa.list_(pa.bool_()))
+        table = pa.Table.from_arrays([array], names=['col1'])
+        df = table.to_pandas()
+
+        expected_df = pd.DataFrame({'col1': [[True, False], [True]]})
+        tm.assert_frame_equal(df, expected_df)
+
     def test_column_of_lists(self):
         df, schema = dataframe_with_lists()
         _check_pandas_roundtrip(df, schema=schema, expected_schema=schema)