You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ks...@apache.org on 2019/02/15 11:58:50 UTC
[arrow] branch master updated: ARROW-3669: [Python] Raise error on
Numpy byte-swapped array
This is an automated email from the ASF dual-hosted git repository.
kszucs 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 40b0c88 ARROW-3669: [Python] Raise error on Numpy byte-swapped array
40b0c88 is described below
commit 40b0c88838b692518fec80835c70233629010e31
Author: Antoine Pitrou <an...@python.org>
AuthorDate: Fri Feb 15 12:58:33 2019 +0100
ARROW-3669: [Python] Raise error on Numpy byte-swapped array
Previously we would return an incorrect result.
Author: Antoine Pitrou <an...@python.org>
Closes #3648 from pitrou/ARROW-3669-numpy-byteswapped-arrays and squashes the following commits:
1e0e10de <Antoine Pitrou> ARROW-3669: Raise error on Numpy byte-swapped array
---
cpp/src/arrow/python/numpy_to_arrow.cc | 5 +++++
python/pyarrow/tests/test_convert_pandas.py | 14 ++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/cpp/src/arrow/python/numpy_to_arrow.cc b/cpp/src/arrow/python/numpy_to_arrow.cc
index ef63ccf..8d15024 100644
--- a/cpp/src/arrow/python/numpy_to_arrow.cc
+++ b/cpp/src/arrow/python/numpy_to_arrow.cc
@@ -424,6 +424,11 @@ Status CopyStridedArray(PyArrayObject* arr, const int64_t length, MemoryPool* po
template <typename ArrowType>
inline Status NumPyConverter::PrepareInputData(std::shared_ptr<Buffer>* data) {
+ if (PyArray_ISBYTESWAPPED(arr_)) {
+ // TODO
+ return Status::NotImplemented("Byte-swapped arrays not supported");
+ }
+
if (is_strided()) {
RETURN_NOT_OK(CopyStridedArray<ArrowType>(arr_, length_, pool_, data));
} else if (dtype_->type_num == NPY_BOOL) {
diff --git a/python/pyarrow/tests/test_convert_pandas.py b/python/pyarrow/tests/test_convert_pandas.py
index e904486..fe5b305 100644
--- a/python/pyarrow/tests/test_convert_pandas.py
+++ b/python/pyarrow/tests/test_convert_pandas.py
@@ -607,6 +607,20 @@ class TestConvertPrimitiveTypes(object):
arr = pa.array(np_arr)
assert arr.to_pylist() == np_arr.tolist()
+ def test_integer_byteorder(self):
+ # Byteswapped arrays are not supported yet
+ int_dtypes = ['i1', 'i2', 'i4', 'i8', 'u1', 'u2', 'u4', 'u8']
+ for dt in int_dtypes:
+ for order in '=<>':
+ data = np.array([1, 2, 42], dtype=order + dt)
+ for np_arr in (data, data[::2]):
+ if data.dtype.isnative:
+ arr = pa.array(data)
+ assert arr.to_pylist() == data.tolist()
+ else:
+ with pytest.raises(NotImplementedError):
+ arr = pa.array(data)
+
def test_integer_with_nulls(self):
# pandas requires upcast to float dtype