Skip to content

Commit

Permalink
remove unwrap
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebarron committed Jul 26, 2024
1 parent 435e891 commit 9a2c084
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pyo3-arrow/src/interop/numpy/from_numpy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ use pyo3::exceptions::PyValueError;

use crate::error::PyArrowResult;

// TODO: remove unwrap
pub fn from_numpy(array: &PyUntypedArray, arrow_data_type: DataType) -> PyArrowResult<ArrayRef> {
macro_rules! numpy_to_arrow {
($dtype:ty, $arrow_type:ty) => {{
let arr = array.downcast::<PyArray1<$dtype>>().unwrap();
let arr = array.downcast::<PyArray1<$dtype>>()?;
Ok(Arc::new(PrimitiveArray::<$arrow_type>::from(
arr.to_owned_array().to_vec(),
)))
Expand All @@ -36,7 +35,7 @@ pub fn from_numpy(array: &PyUntypedArray, arrow_data_type: DataType) -> PyArrowR
DataType::Int32 => numpy_to_arrow!(i32, Int32Type),
DataType::Int64 => numpy_to_arrow!(i64, Int64Type),
DataType::Boolean => {
let arr = array.downcast::<PyArray1<bool>>().unwrap();
let arr = array.downcast::<PyArray1<bool>>()?;
let buffer = BooleanBuffer::from(arr.to_owned_array().to_vec());
Ok(Arc::new(BooleanArray::new(buffer, None)))
}
Expand Down

0 comments on commit 9a2c084

Please sign in to comment.