@@ -33,7 +33,6 @@ use vortex::dtype::DType;
3333use vortex:: dtype:: Nullability ;
3434use vortex:: dtype:: PType ;
3535use vortex:: dtype:: match_each_integer_ptype;
36- use vortex:: error:: VortexError ;
3736use vortex:: ipc:: messages:: EncoderMessage ;
3837use vortex:: ipc:: messages:: MessageEncoder ;
3938
@@ -43,6 +42,7 @@ use crate::arrays::py::PyPythonArray;
4342use crate :: arrays:: py:: PythonArray ;
4443use crate :: arrow:: ToPyArrow ;
4544use crate :: dtype:: PyDType ;
45+ use crate :: error:: PyVortexError ;
4646use crate :: install_module;
4747use crate :: python_repr:: PythonRepr ;
4848use crate :: scalar:: PyScalar ;
@@ -112,7 +112,7 @@ impl<'py> FromPyObject<'_, 'py> for PyArrayRef {
112112impl < ' py > IntoPyObject < ' py > for PyArrayRef {
113113 type Target = PyAny ;
114114 type Output = Bound < ' py , PyAny > ;
115- type Error = VortexError ;
115+ type Error = PyVortexError ;
116116
117117 fn into_pyobject ( self , py : Python < ' py > ) -> Result < Self :: Output , Self :: Error > {
118118 // If the ArrayRef is a PyArrayInstance, extract the Python object.
@@ -214,7 +214,7 @@ impl PyArray {
214214 /// -------
215215 /// :class:`~vortex.Array`
216216 #[ staticmethod]
217- fn from_arrow ( obj : Bound < ' _ , PyAny > ) -> PyResult < PyArrayRef > {
217+ fn from_arrow ( obj : Bound < ' _ , PyAny > ) -> Result < PyArrayRef , PyVortexError > {
218218 from_arrow:: from_arrow ( & obj. as_borrowed ( ) )
219219 }
220220
@@ -257,7 +257,10 @@ impl PyArray {
257257 /// ```
258258 #[ staticmethod]
259259 #[ pyo3( signature = ( range, * , dtype = None ) ) ]
260- fn from_range ( range : Bound < PyAny > , dtype : Option < Bound < PyDType > > ) -> PyResult < PyArrayRef > {
260+ fn from_range (
261+ range : Bound < PyAny > ,
262+ dtype : Option < Bound < PyDType > > ,
263+ ) -> Result < PyArrayRef , PyVortexError > {
261264 let range = range. cast :: < PyRange > ( ) ?;
262265 let start = range. start ( ) ?;
263266 let stop = range. stop ( ) ?;
@@ -268,7 +271,8 @@ impl PyArray {
268271 let DType :: Primitive ( ptype, ..) = & dtype else {
269272 return Err ( PyValueError :: new_err (
270273 "Cannot construct non-numeric array from a range." ,
271- ) ) ;
274+ )
275+ . into ( ) ) ;
272276 } ;
273277 ( * ptype, dtype)
274278 } else {
@@ -313,7 +317,9 @@ impl PyArray {
313317 /// ]
314318 /// ```
315319 ///
316- fn to_arrow_array < ' py > ( self_ : & ' py Bound < ' py , Self > ) -> PyResult < Bound < ' py , PyAny > > {
320+ fn to_arrow_array < ' py > (
321+ self_ : & ' py Bound < ' py , Self > ,
322+ ) -> Result < Bound < ' py , PyAny > , PyVortexError > {
317323 // NOTE(ngates): for struct arrays, we could also return a RecordBatchStreamReader.
318324 let array = PyArrayRef :: extract ( self_. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
319325 let py = self_. py ( ) ;
@@ -326,8 +332,10 @@ impl PyArray {
326332 let chunks = chunked_array
327333 . chunks ( )
328334 . iter ( )
329- . map ( |chunk| PyResult :: Ok ( chunk. clone ( ) . into_arrow ( & arrow_dtype) ?) )
330- . collect :: < PyResult < Vec < ArrowArrayRef > > > ( ) ?;
335+ . map ( |chunk| -> Result < _ , PyVortexError > {
336+ Ok ( chunk. clone ( ) . into_arrow ( & arrow_dtype) ?)
337+ } )
338+ . collect :: < Result < Vec < ArrowArrayRef > , _ > > ( ) ?;
331339
332340 let pa_data_type = arrow_dtype. clone ( ) . to_pyarrow ( py) ?;
333341 let chunks = chunks
@@ -339,11 +347,11 @@ impl PyArray {
339347 PyDict :: from_sequence ( & PyList :: new ( py, vec ! [ ( "type" , pa_data_type) ] ) ?. into_any ( ) ) ?;
340348
341349 // Combine into a chunked array
342- PyModule :: import ( py, "pyarrow" ) ?. call_method (
350+ Ok ( PyModule :: import ( py, "pyarrow" ) ?. call_method (
343351 "chunked_array" ,
344352 ( PyList :: new ( py, chunks) ?, ) ,
345353 Some ( & kwargs) ,
346- )
354+ ) ? )
347355 } else {
348356 Ok ( array
349357 . clone ( )
@@ -417,42 +425,42 @@ impl PyArray {
417425 }
418426
419427 ///Rust docs are *not* copied into Python for __lt__: https://github.com/PyO3/pyo3/issues/4326
420- fn __lt__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
428+ fn __lt__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
421429 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
422430 let inner = compare ( & slf, & * other, Operator :: Lt ) ?;
423431 Ok ( PyArrayRef :: from ( inner) )
424432 }
425433
426434 ///Rust docs are *not* copied into Python for __le__: https://github.com/PyO3/pyo3/issues/4326
427- fn __le__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
435+ fn __le__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
428436 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
429437 let inner = compare ( & * slf, & * other, Operator :: Lte ) ?;
430438 Ok ( PyArrayRef :: from ( inner) )
431439 }
432440
433441 ///Rust docs are *not* copied into Python for __eq__: https://github.com/PyO3/pyo3/issues/4326
434- fn __eq__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
442+ fn __eq__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
435443 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
436444 let inner = compare ( & * slf, & * other, Operator :: Eq ) ?;
437445 Ok ( PyArrayRef :: from ( inner) )
438446 }
439447
440448 ///Rust docs are *not* copied into Python for __ne__: https://github.com/PyO3/pyo3/issues/4326
441- fn __ne__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
449+ fn __ne__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
442450 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
443451 let inner = compare ( & * slf, & * other, Operator :: NotEq ) ?;
444452 Ok ( PyArrayRef :: from ( inner) )
445453 }
446454
447455 ///Rust docs are *not* copied into Python for __ge__: https://github.com/PyO3/pyo3/issues/4326
448- fn __ge__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
456+ fn __ge__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
449457 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
450458 let inner = compare ( & * slf, & * other, Operator :: Gte ) ?;
451459 Ok ( PyArrayRef :: from ( inner) )
452460 }
453461
454462 ///Rust docs are *not* copied into Python for __gt__: https://github.com/PyO3/pyo3/issues/4326
455- fn __gt__ ( slf : Bound < Self > , other : PyArrayRef ) -> PyResult < PyArrayRef > {
463+ fn __gt__ ( slf : Bound < Self > , other : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
456464 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
457465 let inner = compare ( & * slf, & * other, Operator :: Gt ) ?;
458466 Ok ( PyArrayRef :: from ( inner) )
@@ -486,7 +494,7 @@ impl PyArray {
486494 /// 5
487495 /// ]
488496 /// ```
489- fn filter ( slf : Bound < Self > , mask : PyArrayRef ) -> PyResult < PyArrayRef > {
497+ fn filter ( slf : Bound < Self > , mask : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
490498 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
491499 let mask = ( & * mask as & dyn Array ) . to_bool ( ) . to_mask_fill_null_false ( ) ;
492500 let inner = vortex:: compute:: filter ( & * slf, & mask) ?;
@@ -612,14 +620,15 @@ impl PyArray {
612620 /// "a"
613621 /// ]
614622 /// ```
615- fn take ( slf : Bound < Self > , indices : PyArrayRef ) -> PyResult < PyArrayRef > {
623+ fn take ( slf : Bound < Self > , indices : PyArrayRef ) -> Result < PyArrayRef , PyVortexError > {
616624 let slf = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?. into_inner ( ) ;
617625
618626 if !indices. dtype ( ) . is_int ( ) {
619627 return Err ( PyValueError :: new_err ( format ! (
620628 "indices: expected int or uint array, but found: {}" ,
621629 indices. dtype( ) . python_repr( )
622- ) ) ) ;
630+ ) )
631+ . into ( ) ) ;
623632 }
624633
625634 let inner = take ( & slf, & * indices) ?;
@@ -669,7 +678,7 @@ impl PyArray {
669678 . to_string ( ) )
670679 }
671680
672- fn serialize ( slf : & Bound < Self > , ctx : & PyArrayContext ) -> PyResult < Vec < Vec < u8 > > > {
681+ fn serialize ( slf : & Bound < Self > , ctx : & PyArrayContext ) -> Result < Vec < Vec < u8 > > , PyVortexError > {
673682 // FIXME(ngates): do not copy to vec, use buffer protocol
674683 let array = PyArrayRef :: extract ( slf. as_any ( ) . as_borrowed ( ) ) ?;
675684 Ok ( array
0 commit comments