Skip to content

Commit

Permalink
Add last bits that crashed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
raulcd committed Jun 12, 2024
1 parent 3ac349e commit 79533e8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions python/pyarrow/array.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,9 @@ cdef class Array(_PandasConvertible):
-------
array : numpy.ndarray
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef:
PyObject* out
PandasOptions c_options
Expand Down
2 changes: 1 addition & 1 deletion python/pyarrow/src/arrow/python/python_to_arrow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ class PyValue {
default:
return Status::UnknownError("Invalid time unit");
}
} else if (PyArray_CheckAnyScalarExact(obj)) {
} else if (has_numpy() && PyArray_CheckAnyScalarExact(obj)) {
// validate that the numpy scalar has np.datetime64 dtype
ARROW_ASSIGN_OR_RAISE(auto numpy_type, NumPyScalarToArrowDataType(obj));
if (!numpy_type->Equals(*type)) {
Expand Down
3 changes: 3 additions & 0 deletions python/pyarrow/table.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,9 @@ cdef class ChunkedArray(_PandasConvertible):
>>> n_legs.to_numpy()
array([ 2, 2, 4, 4, 5, 100])
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
if zero_copy_only:
raise ValueError(
"zero_copy_only must be False for pyarrow.ChunkedArray.to_numpy"
Expand Down
15 changes: 15 additions & 0 deletions python/pyarrow/tensor.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ strides: {0.strides}""".format(self)
array([[ 2, 2, 4],
[ 4, 5, 100]], dtype=int32)
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef PyObject* out

check_status(TensorToNdarray(self.sp_tensor, self, &out))
Expand Down Expand Up @@ -478,6 +481,9 @@ shape: {0.shape}""".format(self)
"""
Convert arrow::SparseCOOTensor to numpy.ndarrays with zero copy.
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef PyObject* out_data
cdef PyObject* out_coords

Expand Down Expand Up @@ -743,6 +749,9 @@ shape: {0.shape}""".format(self)
"""
Convert arrow::SparseCSRMatrix to numpy.ndarrays with zero copy.
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef PyObject* out_data
cdef PyObject* out_indptr
cdef PyObject* out_indices
Expand Down Expand Up @@ -981,6 +990,9 @@ shape: {0.shape}""".format(self)
"""
Convert arrow::SparseCSCMatrix to numpy.ndarrays with zero copy
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef PyObject* out_data
cdef PyObject* out_indptr
cdef PyObject* out_indices
Expand Down Expand Up @@ -1216,6 +1228,9 @@ shape: {0.shape}""".format(self)
"""
Convert arrow::SparseCSFTensor to numpy.ndarrays with zero copy
"""
if not HAS_NUMPY:
raise ValueError(
"Cannot return a numpy.ndarray if Numpy is not present")
cdef PyObject* out_data
cdef PyObject* out_indptr
cdef PyObject* out_indices
Expand Down

0 comments on commit 79533e8

Please sign in to comment.