arrow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From w...@apache.org
Subject arrow git commit: ARROW-1222: [Python] Raise exception when passing unsupported Python object type to pyarrow.array
Date Mon, 17 Jul 2017 13:00:58 GMT
Repository: arrow
Updated Branches:
  refs/heads/master 8644ee177 -> e370174dd


ARROW-1222: [Python] Raise exception when passing unsupported Python object type to pyarrow.array

Author: Wes McKinney <wes.mckinney@twosigma.com>

Closes #854 from wesm/ARROW-1222 and squashes the following commits:

f1a9fc40 [Wes McKinney] Raise exception when passing unsupported Python object type to pyarrow.array


Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/e370174d
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/e370174d
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/e370174d

Branch: refs/heads/master
Commit: e370174dd4568a25264da1e531af359c205546ab
Parents: 8644ee1
Author: Wes McKinney <wes.mckinney@twosigma.com>
Authored: Mon Jul 17 09:00:54 2017 -0400
Committer: Wes McKinney <wes.mckinney@twosigma.com>
Committed: Mon Jul 17 09:00:54 2017 -0400

----------------------------------------------------------------------
 cpp/src/arrow/python/builtin_convert.cc | 11 +++++++++--
 python/pyarrow/tests/test_array.py      |  7 +++++++
 2 files changed, 16 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/arrow/blob/e370174d/cpp/src/arrow/python/builtin_convert.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/python/builtin_convert.cc b/cpp/src/arrow/python/builtin_convert.cc
index 83154bb..fa1c734 100644
--- a/cpp/src/arrow/python/builtin_convert.cc
+++ b/cpp/src/arrow/python/builtin_convert.cc
@@ -83,7 +83,7 @@ class ScalarVisitor {
         binary_count_(0),
         unicode_count_(0) {}
 
-  void Visit(PyObject* obj) {
+  Status Visit(PyObject* obj) {
     ++total_count_;
     if (obj == Py_None) {
       ++none_count_;
@@ -103,7 +103,14 @@ class ScalarVisitor {
       ++unicode_count_;
     } else {
       // TODO(wesm): accumulate error information somewhere
+      static std::string supported_types =
+        "bool, float, integer, date, datetime, bytes, unicode";
+      std::stringstream ss;
+      ss << "Error inferring Arrow data type for collection of Python objects. ";
+      RETURN_NOT_OK(InvalidConversion(obj, supported_types, &ss));
+      return Status::Invalid(ss.str());
     }
+    return Status::OK();
   }
 
   std::shared_ptr<DataType> GetType() {
@@ -256,7 +263,7 @@ class SeqVisitor {
         // TODO
       } else {
         ++nesting_histogram_[level];
-        scalars_.Visit(item_ref.obj());
+        return scalars_.Visit(item_ref.obj());
       }
     }
     return Status::OK();

http://git-wip-us.apache.org/repos/asf/arrow/blob/e370174d/python/pyarrow/tests/test_array.py
----------------------------------------------------------------------
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index 413a3be..1a0ee61 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import datetime
 import pytest
 import sys
 
@@ -142,6 +143,12 @@ def test_array_slice():
         arr[::2]
 
 
+def test_array_factory_invalid_type():
+    arr = np.array([datetime.timedelta(1), datetime.timedelta(2)])
+    with pytest.raises(ValueError):
+        pa.array(arr)
+
+
 def test_dictionary_from_numpy():
     indices = np.repeat([0, 1, 2], 2)
     dictionary = np.array(['foo', 'bar', 'baz'], dtype=object)


Mime
View raw message