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

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

wesm closed pull request #1587: ARROW-2128: [Python] Support arrays of empty 
lists
URL: https://github.com/apache/arrow/pull/1587
 
 
   

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/cpp/src/arrow/python/builtin_convert.cc 
b/cpp/src/arrow/python/builtin_convert.cc
index f0e5449b6..60f58ea5b 100644
--- a/cpp/src/arrow/python/builtin_convert.cc
+++ b/cpp/src/arrow/python/builtin_convert.cc
@@ -200,22 +200,18 @@ class SeqVisitor {
 
   std::shared_ptr<DataType> GetType() {
     // If all the non-list inputs were null (or there were no inputs)
+    std::shared_ptr<DataType> result;
     if (scalars_.total_count() == 0) {
-      if (max_nesting_level_ == 0) {
-        // If its just a single empty list or list of nulls, return null.
-        return null();
-      } else {
-        // Error, if we have nesting but no concrete base type.
-        return nullptr;
-      }
+      // Lists of Lists of NULL
+      result = null();
     } else {
       // Lists of Lists of [X]
-      std::shared_ptr<DataType> result = scalars_.GetType();
-      for (int i = 0; i < max_nesting_level_; ++i) {
-        result = std::make_shared<ListType>(result);
-      }
-      return result;
+      result = scalars_.GetType();
     }
+    for (int i = 0; i < max_nesting_level_; ++i) {
+      result = std::make_shared<ListType>(result);
+    }
+    return result;
   }
 
   Status Validate() const {
diff --git a/python/pyarrow/tests/test_convert_pandas.py 
b/python/pyarrow/tests/test_convert_pandas.py
index 7dbf0d7ed..53e37f539 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -851,6 +851,14 @@ def test_nested_lists_all_none(self):
         expected = pa.array([None, None, [None, None], [None, None]])
         assert arr.equals(expected)
 
+    def test_nested_lists_all_empty(self):
+        # ARROW-2128
+        data = pd.Series([[], [], []])
+        arr = pa.array(data)
+        expected = pa.array(list(data))
+        assert arr.equals(expected)
+        assert arr.type == pa.list_(pa.null())
+
     def test_threaded_conversion(self):
         df = _alltypes_example()
         _check_pandas_roundtrip(df, nthreads=2)


 

----------------------------------------------------------------
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:
[email protected]


> [Python] Cannot serialize array of empty lists
> ----------------------------------------------
>
>                 Key: ARROW-2128
>                 URL: https://issues.apache.org/jira/browse/ARROW-2128
>             Project: Apache Arrow
>          Issue Type: Bug
>          Components: Python
>    Affects Versions: 0.8.0
>            Reporter: Uwe L. Korn
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 0.9.0
>
>
> This currently failing:
> {code:java}
> data = pd.Series([[], [], []])
> arr = pa.array(data)
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _
> array.pxi:181: in pyarrow.lib.array
> ???
> array.pxi:26: in pyarrow.lib._sequence_to_array
> ???
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
> _
> > ???
> E pyarrow.lib.ArrowTypeError: Unable to determine data type
> {code}
> The code in {{SeqVisitor::GetType}} suggests that we don't want to support 
> thus but I would have expected that the above should result in {{List<Null>}}.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to