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 2019/06/03 14:12:33 UTC

[arrow] branch master updated: ARROW-5430: [Python] Raise ArrowInvalid for pyints larger than int64

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 5f84c9c  ARROW-5430: [Python] Raise ArrowInvalid for pyints larger than int64
5f84c9c is described below

commit 5f84c9c713a56c6e52fdead7e61afc39ba327209
Author: Robin Kåveland Hansen <Ro...@posten.no>
AuthorDate: Mon Jun 3 16:12:21 2019 +0200

    ARROW-5430: [Python] Raise ArrowInvalid for pyints larger than int64
    
    Previously, this case would cause ArrowException: Unknown error, but ArrowInvalid makes more sense and is more likely to be dealt with by callers of pyarrow.array.
    
    Author: Robin Kåveland Hansen <Ro...@posten.no>
    
    Closes #4440 from kaaveland/master and squashes the following commits:
    
    b95aa0253 <Robin Kåveland Hansen> ARROW-5430:  Raise ArrowInvalid for pyints larger than int64
---
 cpp/src/arrow/python/common.cc     | 3 ++-
 python/pyarrow/tests/test_array.py | 7 +++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/cpp/src/arrow/python/common.cc b/cpp/src/arrow/python/common.cc
index 1d4b3ab..8f844e6 100644
--- a/cpp/src/arrow/python/common.cc
+++ b/cpp/src/arrow/python/common.cc
@@ -113,7 +113,8 @@ Status ConvertPyError(StatusCode code) {
       code = StatusCode::KeyError;
     } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_TypeError)) {
       code = StatusCode::TypeError;
-    } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_ValueError)) {
+    } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_ValueError) ||
+               PyErr_GivenExceptionMatches(exc_type, PyExc_OverflowError)) {
       code = StatusCode::Invalid;
     } else if (PyErr_GivenExceptionMatches(exc_type, PyExc_EnvironmentError)) {
       code = StatusCode::IOError;
diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py
index f59301c..9e4132a 100644
--- a/python/pyarrow/tests/test_array.py
+++ b/python/pyarrow/tests/test_array.py
@@ -1374,3 +1374,10 @@ def test_numpy_string_overflow_to_chunked():
         for val in chunk:
             assert val.as_py() == values[value_index]
             value_index += 1
+
+
+def test_array_from_large_pyints():
+    # ARROW-5430
+    with pytest.raises(pa.ArrowInvalid):
+        # too large for int64 so dtype must be explicitly provided
+        pa.array([int(2 ** 63)])