This is an automated email from the ASF dual-hosted git repository. uwe 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 8443759 ARROW-2871: [Python] Raise when calling to_numpy() on boolean array 8443759 is described below commit 8443759d03e9e4c9c7fc7dc4bd547d9d9143013f Author: Wes McKinney <wesm+...@apache.org> AuthorDate: Wed Jul 18 15:27:50 2018 +0200 ARROW-2871: [Python] Raise when calling to_numpy() on boolean array Also marks that `to_numpy` API is experimental, since we need to figure out what to do about nulls (ARROW-2870) Author: Wes McKinney <wesm+...@apache.org> Closes #2277 from wesm/ARROW-2871 and squashes the following commits: c07b9b48 <Wes McKinney> Boolean is not supported in Array.to_numpy --- python/pyarrow/array.pxi | 11 +++++++++-- python/pyarrow/tests/test_array.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/python/pyarrow/array.pxi b/python/pyarrow/array.pxi index c2eb870..f209eb7 100644 --- a/python/pyarrow/array.pxi +++ b/python/pyarrow/array.pxi @@ -606,12 +606,19 @@ cdef class Array: def to_numpy(self): """ - Construct a NumPy view of this array + EXPERIMENTAL: Construct a NumPy view of this array. Only supports + primitive arrays with the same memory layout as NumPy (i.e. integers, + floating point) without any nulls. + + Returns + ------- + arr : numpy.ndarray + """ if self.null_count: raise NotImplementedError('NumPy array view is only supported ' 'for arrays without nulls.') - if not is_primitive(self.type.id): + if not is_primitive(self.type.id) or self.type.id == _Type_BOOL: raise NotImplementedError('NumPy array view is only supported ' 'for primitive types.') buflist = self.buffers() diff --git a/python/pyarrow/tests/test_array.py b/python/pyarrow/tests/test_array.py index 29583e8..da3b247 100644 --- a/python/pyarrow/tests/test_array.py +++ b/python/pyarrow/tests/test_array.py @@ -108,6 +108,19 @@ def test_to_numpy_zero_copy(): np.testing.assert_array_equal(np_arr, expected) +def test_to_numpy_unsupported_types(): + # ARROW-2871: Some primitive types are not yet supported in to_numpy + bool_arr = pa.array([True, False, True]) + + with pytest.raises(NotImplementedError): + bool_arr.to_numpy() + + null_arr = pa.array([None, None, None]) + + with pytest.raises(NotImplementedError): + null_arr.to_numpy() + + def test_to_pandas_zero_copy(): import gc