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 2018/01/02 16:30:49 UTC

[arrow] branch master updated: ARROW-1941: [Python] Fix empty list roundtrip in 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 4a3e6e3  ARROW-1941: [Python] Fix empty list roundtrip in to_pandas
4a3e6e3 is described below

commit 4a3e6e361685cc3350e679ef3461103ffc4df0a2
Author: Licht-T <li...@outlook.jp>
AuthorDate: Tue Jan 2 11:30:45 2018 -0500

    ARROW-1941: [Python] Fix empty list roundtrip in to_pandas
    
    This closes [ARROW-1941](https://issues.apache.org/jira/browse/ARROW-1941).
    
    Author: Licht-T <li...@outlook.jp>
    
    Closes #1449 from Licht-T/fix-empty-list-roundtrip and squashes the following commits:
    
    165dc6f [Licht-T] TST: Add test for the empty list roundtrip
    0ddfd87 [Licht-T] BUG: Fix empty list roundtrip
---
 cpp/src/arrow/python/arrow_to_pandas.cc     |  2 ++
 python/pyarrow/tests/test_convert_pandas.py | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/cpp/src/arrow/python/arrow_to_pandas.cc b/cpp/src/arrow/python/arrow_to_pandas.cc
index 08ce37c..e21bbda 100644
--- a/cpp/src/arrow/python/arrow_to_pandas.cc
+++ b/cpp/src/arrow/python/arrow_to_pandas.cc
@@ -90,6 +90,7 @@ struct WrapBytes<FixedSizeBinaryArray> {
 
 static inline bool ListTypeSupported(const DataType& type) {
   switch (type.id()) {
+    case Type::NA:
     case Type::UINT8:
     case Type::INT8:
     case Type::UINT16:
@@ -695,6 +696,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(FloatType, NA)
         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 7609d34..76b55cf 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -1317,6 +1317,18 @@ class TestPandasConversion(object):
             result = table_subset2.to_pandas()
             tm.assert_frame_equal(result, df[['a']].reset_index(drop=True))
 
+    def test_empty_list_roundtrip(self):
+        empty_list_array = np.empty((3,), dtype=object)
+        empty_list_array.fill([])
+
+        df = pd.DataFrame({'a': np.array(['1', '2', '3']),
+                           'b': empty_list_array})
+        tbl = pa.Table.from_pandas(df)
+
+        result = tbl.to_pandas()
+
+        tm.assert_frame_equal(result, df)
+
 
 def _fully_loaded_dataframe_example():
     from distutils.version import LooseVersion

-- 
To stop receiving notification emails like this one, please contact
['"commits@arrow.apache.org" <co...@arrow.apache.org>'].