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

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

pitrou closed pull request #1906: ARROW-2443: [Python] Allow creation of empty 
Dictionary indices
URL: https://github.com/apache/arrow/pull/1906
 
 
   

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/array.cc b/cpp/src/arrow/array.cc
index c3fb04bbc..710821e1d 100644
--- a/cpp/src/arrow/array.cc
+++ b/cpp/src/arrow/array.cc
@@ -581,10 +581,6 @@ DictionaryArray::DictionaryArray(const 
std::shared_ptr<DataType>& type,
 Status DictionaryArray::FromArrays(const std::shared_ptr<DataType>& type,
                                    const std::shared_ptr<Array>& indices,
                                    std::shared_ptr<Array>* out) {
-  if (indices->length() == 0) {
-    return Status::Invalid("Dictionary indices must have non-zero length");
-  }
-
   DCHECK_EQ(type->id(), Type::DICTIONARY);
   const auto& dict = static_cast<const DictionaryType&>(*type);
   DCHECK_EQ(indices->type_id(), dict.index_type()->id());
diff --git a/python/pyarrow/tests/test_convert_pandas.py 
b/python/pyarrow/tests/test_convert_pandas.py
index 7f9ede969..6970975cc 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -1836,6 +1836,11 @@ def test_category(self):
         for values in arrays:
             _check_array_roundtrip(values)
 
+    def test_empty_category(self):
+        # ARROW-2443
+        df = pd.DataFrame({'cat': pd.Categorical([])})
+        _check_pandas_roundtrip(df)
+
     def test_mixed_types_fails(self):
         data = pd.DataFrame({'a': ['a', 1, 2.0]})
         with pytest.raises(pa.ArrowException):


 

----------------------------------------------------------------
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] Conversion from pandas of empty categorical fails with ArrowInvalid
> ----------------------------------------------------------------------------
>
>                 Key: ARROW-2443
>                 URL: https://issues.apache.org/jira/browse/ARROW-2443
>             Project: Apache Arrow
>          Issue Type: Bug
>    Affects Versions: 0.9.0
>            Reporter: Florian Jetter
>            Assignee: Uwe L. Korn
>            Priority: Minor
>              Labels: pull-request-available
>             Fix For: 0.10.0
>
>
> The conversion of an empty pandas categorical raises an exception. Before 
> version `0.9.0` this was possible
> {code:java}
> import pandas as pd
> import pyarrow as pa
> pa.Table.from_pandas(pd.DataFrame({'cat': pd.Categorical([])})){code}
> raises:
> {{ArrowInvalid: Dictionary indices must have non-zero length}}



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

Reply via email to