Skip to content

Commit 46c19a5

Browse files
committed
Remove the 'python' feature from vortex-error
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 88d0f4d commit 46c19a5

File tree

31 files changed

+201
-131
lines changed

31 files changed

+201
-131
lines changed

vortex-error/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ all-features = true
1818

1919
[features]
2020
flatbuffers = ["dep:flatbuffers"]
21-
python = ["dep:pyo3"]
2221
serde = ["dep:serde_json"]
2322

2423
[dependencies]

vortex-error/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
//! This crate defines error & result types for Vortex.
77
//! It also contains a variety of useful macros for error handling.
88
9-
#[cfg(feature = "python")]
10-
pub mod python;
11-
129
use std::backtrace::Backtrace;
1310
use std::borrow::Cow;
1411
use std::convert::Infallible;

vortex-error/src/python.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

vortex-python/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ tokio = { workspace = true, features = ["fs", "rt-multi-thread"] }
4343
# This feature makes the underlying tracing logs to be emitted as `log` events
4444
tracing = { workspace = true, features = ["std", "log"] }
4545
url = { workspace = true }
46-
vortex = { workspace = true, features = ["object_store", "python", "tokio"] }
46+
vortex = { workspace = true, features = ["object_store", "tokio"] }
4747

4848
[dev-dependencies]
4949
vortex-array = { workspace = true, features = ["_test-harness"] }

vortex-python/src/arrays/builtins/struct_.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::arrays::PyArrayRef;
1212
use crate::arrays::native::AsArrayRef;
1313
use crate::arrays::native::EncodingSubclass;
1414
use crate::arrays::native::PyNativeArray;
15+
use crate::error::PyVortexError;
1516

1617
/// Concrete class for arrays with `vortex.struct` encoding.
1718
#[pyclass(name = "StructArray", module = "vortex", extends=PyNativeArray, frozen)]
@@ -24,7 +25,7 @@ impl EncodingSubclass for PyStructArray {
2425
#[pymethods]
2526
impl PyStructArray {
2627
/// Returns the given field of the struct array.
27-
pub fn field(self_: PyRef<'_, Self>, name: &str) -> PyResult<PyArrayRef> {
28+
pub fn field(self_: PyRef<'_, Self>, name: &str) -> Result<PyArrayRef, PyVortexError> {
2829
let field = self_.as_array_ref().field_by_name(name)?.clone();
2930
Ok(PyArrayRef::from(field))
3031
}

vortex-python/src/arrays/compressed.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::PyVortex;
1919
use crate::arrays::PyArrayRef;
2020
use crate::arrays::native::EncodingSubclass;
2121
use crate::arrays::native::PyNativeArray;
22+
use crate::error::PyVortexError;
2223

2324
/// Concrete class for arrays with `vortex.alp` encoding.
2425
#[pyclass(name = "AlpArray", module = "vortex", extends=PyNativeArray, frozen)]
@@ -87,7 +88,7 @@ impl EncodingSubclass for PyZigZagArray {
8788
#[pymethods]
8889
impl PyZigZagArray {
8990
#[staticmethod]
90-
pub fn encode(array: PyArrayRef) -> PyResult<PyArrayRef> {
91+
pub fn encode(array: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
9192
Ok(PyVortex(
9293
zigzag_encode(array.inner().clone().to_primitive())?.into_array(),
9394
))

vortex-python/src/arrays/from_arrow.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use arrow_array::make_array;
77
use arrow_data::ArrayData as ArrowArrayData;
88
use arrow_schema::DataType;
99
use arrow_schema::Field;
10-
use itertools::Itertools;
1110
use pyo3::exceptions::PyValueError;
1211
use pyo3::prelude::*;
1312
use vortex::array::ArrayRef;
@@ -17,13 +16,13 @@ use vortex::array::arrow::FromArrowArray;
1716
use vortex::dtype::DType;
1817
use vortex::dtype::arrow::FromArrowType;
1918
use vortex::error::VortexError;
20-
use vortex::error::VortexResult;
2119

2220
use crate::arrays::PyArrayRef;
2321
use crate::arrow::FromPyArrow;
22+
use crate::error::PyVortexError;
2423

2524
/// Convert an Arrow object to a Vortex array.
26-
pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> PyResult<PyArrayRef> {
25+
pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> Result<PyArrayRef, PyVortexError> {
2726
let pa = obj.py().import("pyarrow")?;
2827
let pa_array = pa.getattr("Array")?;
2928
let chunked_array = pa.getattr("ChunkedArray")?;
@@ -56,15 +55,14 @@ pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> PyResult<PyArrayRef>
5655
let dtype = DType::from_arrow(array_stream.schema());
5756
let chunks = array_stream
5857
.into_iter()
59-
.map(|b| b.map_err(VortexError::from))
60-
.map_ok(|b| ArrayRef::from_arrow(b, false))
61-
.collect::<VortexResult<Vec<_>>>()?;
58+
.map(|b| -> Result<_, PyVortexError> {
59+
Ok(ArrayRef::from_arrow(b.map_err(VortexError::from)?, false))
60+
})
61+
.collect::<Result<Vec<_>, _>>()?;
6262
Ok(PyArrayRef::from(
6363
ChunkedArray::try_new(chunks, dtype)?.into_array(),
6464
))
6565
} else {
66-
Err(PyValueError::new_err(
67-
"Cannot convert object to Vortex array",
68-
))
66+
Err(PyValueError::new_err("Cannot convert object to Vortex array").into())
6967
}
7068
}

vortex-python/src/arrays/into_array.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use pyo3::Borrowed;
99
use pyo3::FromPyObject;
1010
use pyo3::PyAny;
1111
use pyo3::PyErr;
12+
use pyo3::exceptions::PyRuntimeError;
1213
use pyo3::exceptions::PyTypeError;
1314
use pyo3::types::PyAnyMethods;
1415
use vortex::array::ArrayRef;
@@ -17,6 +18,7 @@ use vortex::array::iter::ArrayIteratorAdapter;
1718
use vortex::array::iter::ArrayIteratorExt;
1819
use vortex::dtype::DType;
1920
use vortex::dtype::arrow::FromArrowType as _;
21+
use vortex::error::VortexError;
2022
use vortex::error::VortexResult;
2123

2224
use crate::PyVortex;
@@ -64,9 +66,14 @@ impl<'py> FromPyObject<'_, 'py> for PyIntoArray {
6466
let vortex_iter = arrow_stream
6567
.into_iter()
6668
.map(|batch_result| -> VortexResult<_> {
67-
Ok(ArrayRef::from_arrow(batch_result?, false))
69+
Ok(ArrayRef::from_arrow(
70+
batch_result.map_err(VortexError::from)?,
71+
false,
72+
))
6873
});
69-
let array = ArrayIteratorAdapter::new(dtype, vortex_iter).read_all()?;
74+
let array = ArrayIteratorAdapter::new(dtype, vortex_iter)
75+
.read_all()
76+
.map_err(|e| PyRuntimeError::new_err(e.to_string()))?;
7077
return Ok(PyIntoArray(PyVortex(array)));
7178
}
7279

vortex-python/src/arrays/mod.rs

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ use vortex::dtype::DType;
3333
use vortex::dtype::Nullability;
3434
use vortex::dtype::PType;
3535
use vortex::dtype::match_each_integer_ptype;
36-
use vortex::error::VortexError;
3736
use vortex::ipc::messages::EncoderMessage;
3837
use vortex::ipc::messages::MessageEncoder;
3938

@@ -43,6 +42,7 @@ use crate::arrays::py::PyPythonArray;
4342
use crate::arrays::py::PythonArray;
4443
use crate::arrow::ToPyArrow;
4544
use crate::dtype::PyDType;
45+
use crate::error::PyVortexError;
4646
use crate::install_module;
4747
use crate::python_repr::PythonRepr;
4848
use crate::scalar::PyScalar;
@@ -112,7 +112,7 @@ impl<'py> FromPyObject<'_, 'py> for PyArrayRef {
112112
impl<'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

vortex-python/src/arrays/py/array.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use pyo3::prelude::*;
1111
use vortex::array::stats::ArrayStats;
1212
use vortex::array::vtable::ArrayId;
1313
use vortex::dtype::DType;
14-
use vortex::error::VortexError;
1514

1615
use crate::arrays::py::PyPythonArray;
16+
use crate::error::PyVortexError;
1717

1818
/// Wrapper struct encapsulating a Vortex array implemented using a Python object.
1919
///
@@ -48,7 +48,7 @@ impl<'py> FromPyObject<'_, 'py> for PythonArray {
4848
impl<'py> IntoPyObject<'py> for PythonArray {
4949
type Target = PyAny;
5050
type Output = Bound<'py, PyAny>;
51-
type Error = VortexError;
51+
type Error = PyVortexError;
5252

5353
fn into_pyobject(self, py: Python<'py>) -> Result<Self::Output, Self::Error> {
5454
Ok(self.object.bind(py).to_owned())

0 commit comments

Comments
 (0)