You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ap...@apache.org on 2018/04/19 14:42:52 UTC

[arrow] branch master updated: ARROW-2443: [Python] Allow creation of empty Dictionary indices

This is an automated email from the ASF dual-hosted git repository.

apitrou 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 1299931  ARROW-2443: [Python] Allow creation of empty Dictionary indices
1299931 is described below

commit 129993109c3e3aab4ff7cdabd7265ba9645fe93f
Author: Korn, Uwe <Uw...@blue-yonder.com>
AuthorDate: Thu Apr 19 16:42:38 2018 +0200

    ARROW-2443: [Python] Allow creation of empty Dictionary indices
    
    Empty dictionaries are a valid use case if you have absolutely no data in an array. This was working pre-0.9.0 releases of Arrow.
    
    Author: Korn, Uwe <Uw...@blue-yonder.com>
    
    Closes #1906 from xhochy/ARROW-2443 and squashes the following commits:
    
    5bda740 <Korn, Uwe> ARROW-2443:  Allow creation of empty Dictionary indices
---
 cpp/src/arrow/array.cc                      | 4 ----
 python/pyarrow/tests/test_convert_pandas.py | 5 +++++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/cpp/src/arrow/array.cc b/cpp/src/arrow/array.cc
index c3fb04b..710821e 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 7f9ede9..6970975 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -1836,6 +1836,11 @@ class TestConvertMisc(object):
         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):

-- 
To stop receiving notification emails like this one, please contact
apitrou@apache.org.