Skip to content

Commit 7d06bd1

Browse files
committed
Type alias PyVortexResult
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent af48c30 commit 7d06bd1

File tree

21 files changed

+74
-84
lines changed

21 files changed

+74
-84
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +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;
15+
use crate::error::PyVortexResult;
1616

1717
/// Concrete class for arrays with `vortex.struct` encoding.
1818
#[pyclass(name = "StructArray", module = "vortex", extends=PyNativeArray, frozen)]
@@ -25,7 +25,7 @@ impl EncodingSubclass for PyStructArray {
2525
#[pymethods]
2626
impl PyStructArray {
2727
/// Returns the given field of the struct array.
28-
pub fn field(self_: PyRef<'_, Self>, name: &str) -> Result<PyArrayRef, PyVortexError> {
28+
pub fn field(self_: PyRef<'_, Self>, name: &str) -> PyVortexResult<PyArrayRef> {
2929
let field = self_.as_array_ref().field_by_name(name)?.clone();
3030
Ok(PyArrayRef::from(field))
3131
}

vortex-python/src/arrays/compressed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +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;
22+
use crate::error::PyVortexResult;
2323

2424
/// Concrete class for arrays with `vortex.alp` encoding.
2525
#[pyclass(name = "AlpArray", module = "vortex", extends=PyNativeArray, frozen)]
@@ -88,7 +88,7 @@ impl EncodingSubclass for PyZigZagArray {
8888
#[pymethods]
8989
impl PyZigZagArray {
9090
#[staticmethod]
91-
pub fn encode(array: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
91+
pub fn encode(array: PyArrayRef) -> PyVortexResult<PyArrayRef> {
9292
Ok(PyVortex(
9393
zigzag_encode(array.inner().clone().to_primitive())?.into_array(),
9494
))

vortex-python/src/arrays/from_arrow.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ use vortex::error::VortexError;
1919

2020
use crate::arrays::PyArrayRef;
2121
use crate::arrow::FromPyArrow;
22-
use crate::error::PyVortexError;
22+
use crate::error::PyVortexResult;
2323

2424
/// Convert an Arrow object to a Vortex array.
25-
pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> Result<PyArrayRef, PyVortexError> {
25+
pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> PyVortexResult<PyArrayRef> {
2626
let pa = obj.py().import("pyarrow")?;
2727
let pa_array = pa.getattr("Array")?;
2828
let chunked_array = pa.getattr("ChunkedArray")?;
@@ -55,7 +55,7 @@ pub(super) fn from_arrow(obj: &Borrowed<'_, '_, PyAny>) -> Result<PyArrayRef, Py
5555
let dtype = DType::from_arrow(array_stream.schema());
5656
let chunks = array_stream
5757
.into_iter()
58-
.map(|b| -> Result<_, PyVortexError> {
58+
.map(|b| -> PyVortexResult<_> {
5959
Ok(ArrayRef::from_arrow(b.map_err(VortexError::from)?, false))
6060
})
6161
.collect::<Result<Vec<_>, _>>()?;

vortex-python/src/arrays/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ use crate::arrays::py::PythonArray;
4343
use crate::arrow::ToPyArrow;
4444
use crate::dtype::PyDType;
4545
use crate::error::PyVortexError;
46+
use crate::error::PyVortexResult;
4647
use crate::install_module;
4748
use crate::python_repr::PythonRepr;
4849
use crate::scalar::PyScalar;
@@ -214,7 +215,7 @@ impl PyArray {
214215
/// -------
215216
/// :class:`~vortex.Array`
216217
#[staticmethod]
217-
fn from_arrow(obj: Bound<'_, PyAny>) -> Result<PyArrayRef, PyVortexError> {
218+
fn from_arrow(obj: Bound<'_, PyAny>) -> PyVortexResult<PyArrayRef> {
218219
from_arrow::from_arrow(&obj.as_borrowed())
219220
}
220221

@@ -260,7 +261,7 @@ impl PyArray {
260261
fn from_range(
261262
range: Bound<PyAny>,
262263
dtype: Option<Bound<PyDType>>,
263-
) -> Result<PyArrayRef, PyVortexError> {
264+
) -> PyVortexResult<PyArrayRef> {
264265
let range = range.cast::<PyRange>()?;
265266
let start = range.start()?;
266267
let stop = range.stop()?;
@@ -317,9 +318,7 @@ impl PyArray {
317318
/// ]
318319
/// ```
319320
///
320-
fn to_arrow_array<'py>(
321-
self_: &'py Bound<'py, Self>,
322-
) -> Result<Bound<'py, PyAny>, PyVortexError> {
321+
fn to_arrow_array<'py>(self_: &'py Bound<'py, Self>) -> PyVortexResult<Bound<'py, PyAny>> {
323322
// NOTE(ngates): for struct arrays, we could also return a RecordBatchStreamReader.
324323
let array = PyArrayRef::extract(self_.as_any().as_borrowed())?.into_inner();
325324
let py = self_.py();
@@ -332,9 +331,7 @@ impl PyArray {
332331
let chunks = chunked_array
333332
.chunks()
334333
.iter()
335-
.map(|chunk| -> Result<_, PyVortexError> {
336-
Ok(chunk.clone().into_arrow(&arrow_dtype)?)
337-
})
334+
.map(|chunk| -> PyVortexResult<_> { Ok(chunk.clone().into_arrow(&arrow_dtype)?) })
338335
.collect::<Result<Vec<ArrowArrayRef>, _>>()?;
339336

340337
let pa_data_type = arrow_dtype.clone().to_pyarrow(py)?;
@@ -425,42 +422,42 @@ impl PyArray {
425422
}
426423

427424
///Rust docs are *not* copied into Python for __lt__: https://github.com/PyO3/pyo3/issues/4326
428-
fn __lt__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
425+
fn __lt__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
429426
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
430427
let inner = compare(&slf, &*other, Operator::Lt)?;
431428
Ok(PyArrayRef::from(inner))
432429
}
433430

434431
///Rust docs are *not* copied into Python for __le__: https://github.com/PyO3/pyo3/issues/4326
435-
fn __le__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
432+
fn __le__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
436433
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
437434
let inner = compare(&*slf, &*other, Operator::Lte)?;
438435
Ok(PyArrayRef::from(inner))
439436
}
440437

441438
///Rust docs are *not* copied into Python for __eq__: https://github.com/PyO3/pyo3/issues/4326
442-
fn __eq__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
439+
fn __eq__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
443440
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
444441
let inner = compare(&*slf, &*other, Operator::Eq)?;
445442
Ok(PyArrayRef::from(inner))
446443
}
447444

448445
///Rust docs are *not* copied into Python for __ne__: https://github.com/PyO3/pyo3/issues/4326
449-
fn __ne__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
446+
fn __ne__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
450447
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
451448
let inner = compare(&*slf, &*other, Operator::NotEq)?;
452449
Ok(PyArrayRef::from(inner))
453450
}
454451

455452
///Rust docs are *not* copied into Python for __ge__: https://github.com/PyO3/pyo3/issues/4326
456-
fn __ge__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
453+
fn __ge__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
457454
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
458455
let inner = compare(&*slf, &*other, Operator::Gte)?;
459456
Ok(PyArrayRef::from(inner))
460457
}
461458

462459
///Rust docs are *not* copied into Python for __gt__: https://github.com/PyO3/pyo3/issues/4326
463-
fn __gt__(slf: Bound<Self>, other: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
460+
fn __gt__(slf: Bound<Self>, other: PyArrayRef) -> PyVortexResult<PyArrayRef> {
464461
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
465462
let inner = compare(&*slf, &*other, Operator::Gt)?;
466463
Ok(PyArrayRef::from(inner))
@@ -494,7 +491,7 @@ impl PyArray {
494491
/// 5
495492
/// ]
496493
/// ```
497-
fn filter(slf: Bound<Self>, mask: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
494+
fn filter(slf: Bound<Self>, mask: PyArrayRef) -> PyVortexResult<PyArrayRef> {
498495
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
499496
let mask = (&*mask as &dyn Array).to_bool().to_mask_fill_null_false();
500497
let inner = vortex::compute::filter(&*slf, &mask)?;
@@ -620,7 +617,7 @@ impl PyArray {
620617
/// "a"
621618
/// ]
622619
/// ```
623-
fn take(slf: Bound<Self>, indices: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
620+
fn take(slf: Bound<Self>, indices: PyArrayRef) -> PyVortexResult<PyArrayRef> {
624621
let slf = PyArrayRef::extract(slf.as_any().as_borrowed())?.into_inner();
625622

626623
if !indices.dtype().is_int() {
@@ -678,7 +675,7 @@ impl PyArray {
678675
.to_string())
679676
}
680677

681-
fn serialize(slf: &Bound<Self>, ctx: &PyArrayContext) -> Result<Vec<Vec<u8>>, PyVortexError> {
678+
fn serialize(slf: &Bound<Self>, ctx: &PyArrayContext) -> PyVortexResult<Vec<Vec<u8>>> {
682679
// FIXME(ngates): do not copy to vec, use buffer protocol
683680
let array = PyArrayRef::extract(slf.as_any().as_borrowed())?;
684681
Ok(array

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ pub(crate) use python::*;
1414
use vortex::array::vtable::ArrayId;
1515
pub(crate) use vtable::*;
1616

17-
use crate::error::PyVortexError;
17+
use crate::error::PyVortexResult;
1818

1919
/// Extract the array id from a Python class `id` attribute.
20-
pub fn id_from_obj(cls: &Bound<PyAny>) -> Result<ArrayId, PyVortexError> {
20+
pub fn id_from_obj(cls: &Bound<PyAny>) -> PyVortexResult<ArrayId> {
2121
Ok(ArrayId::new_arc(
2222
cls.getattr("id")
2323
.map_err(|_| {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use vortex::dtype::DType;
1010
use crate::arrays::PyArray;
1111
use crate::arrays::py::id_from_obj;
1212
use crate::dtype::PyDType;
13-
use crate::error::PyVortexError;
13+
use crate::error::PyVortexResult;
1414

1515
/// Base class for implementing a Vortex encoding in Python.
1616
///
@@ -32,7 +32,7 @@ impl PyPythonArray {
3232
cls: &Bound<'_, PyType>,
3333
len: usize,
3434
dtype: PyDType,
35-
) -> Result<PyClassInitializer<Self>, PyVortexError> {
35+
) -> PyVortexResult<PyClassInitializer<Self>> {
3636
let id = id_from_obj(cls)?;
3737
Ok(PyClassInitializer::from(PyArray).add_subclass(Self {
3838
id,

vortex-python/src/compress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pyo3::prelude::*;
55
use vortex::compressor::BtrBlocksCompressor;
66

77
use crate::arrays::PyArrayRef;
8-
use crate::error::PyVortexError;
8+
use crate::error::PyVortexResult;
99
use crate::install_module;
1010

1111
pub(crate) fn init(py: Python, parent: &Bound<PyModule>) -> PyResult<()> {
@@ -50,7 +50,7 @@ pub(crate) fn init(py: Python, parent: &Bound<PyModule>) -> PyResult<()> {
5050
/// >>> str(vx.compress(a))
5151
/// 'vortex.alp(f64?, len=1000)'
5252
#[pyfunction]
53-
pub fn compress(array: PyArrayRef) -> Result<PyArrayRef, PyVortexError> {
53+
pub fn compress(array: PyArrayRef) -> PyVortexResult<PyArrayRef> {
5454
let compressed = BtrBlocksCompressor::default().compress(array.inner())?;
5555
Ok(PyArrayRef::from(compressed))
5656
}

vortex-python/src/dataset.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use crate::TOKIO_RUNTIME;
2929
use crate::arrays::PyArrayRef;
3030
use crate::arrow::IntoPyArrow;
3131
use crate::arrow::ToPyArrow;
32-
use crate::error::PyVortexError;
32+
use crate::error::PyVortexResult;
3333
use crate::expr::PyExpr;
3434
use crate::install_module;
3535
use crate::object_store_urls::object_store_from_url;
@@ -134,7 +134,7 @@ impl PyVortexDataset {
134134
row_filter: Option<&Bound<'py, PyExpr>>,
135135
indices: Option<PyArrayRef>,
136136
row_range: Option<(u64, u64)>,
137-
) -> Result<PyArrayRef, PyVortexError> {
137+
) -> PyVortexResult<PyArrayRef> {
138138
let array = read_array_from_reader(
139139
&self.vxf,
140140
projection_from_python(columns)?,
@@ -152,7 +152,7 @@ impl PyVortexDataset {
152152
row_filter: Option<&Bound<'_, PyExpr>>,
153153
split_by: Option<usize>,
154154
row_range: Option<(u64, u64)>,
155-
) -> Result<Py<PyAny>, PyVortexError> {
155+
) -> PyVortexResult<Py<PyAny>> {
156156
let mut scan = self_
157157
.vxf
158158
.scan()?
@@ -178,7 +178,7 @@ impl PyVortexDataset {
178178
row_filter: Option<&Bound<'_, PyExpr>>,
179179
split_by: Option<usize>,
180180
row_range: Option<(u64, u64)>,
181-
) -> Result<usize, PyVortexError> {
181+
) -> PyVortexResult<usize> {
182182
if row_filter.is_none() {
183183
let row_count = match row_range {
184184
Some(range) => range.1 - range.0,
@@ -210,7 +210,7 @@ impl PyVortexDataset {
210210

211211
/// The natural splits of this Dataset.
212212
#[pyo3(signature = (*))]
213-
pub fn splits(&self) -> Result<Vec<(u64, u64)>, PyVortexError> {
213+
pub fn splits(&self) -> PyVortexResult<Vec<(u64, u64)>> {
214214
Ok(self
215215
.vxf
216216
.splits()?
@@ -221,6 +221,6 @@ impl PyVortexDataset {
221221
}
222222

223223
#[pyfunction]
224-
pub fn dataset_from_url(py: Python, url: &str) -> Result<PyVortexDataset, PyVortexError> {
224+
pub fn dataset_from_url(py: Python, url: &str) -> PyVortexResult<PyVortexDataset> {
225225
Ok(py.detach(|| TOKIO_RUNTIME.block_on(PyVortexDataset::from_url(url)))?)
226226
}

vortex-python/src/dtype/factory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use vortex::dtype::PType;
2121
use vortex::dtype::StructFields;
2222

2323
use crate::dtype::PyDType;
24-
use crate::error::PyVortexError;
24+
use crate::error::PyVortexResult;
2525

2626
/// Construct the data type for a column containing only the null value.
2727
///
@@ -261,7 +261,7 @@ pub(super) fn dtype_decimal(
261261
precision: u8,
262262
scale: i8,
263263
nullable: bool,
264-
) -> Result<Bound<'_, PyDType>, PyVortexError> {
264+
) -> PyVortexResult<Bound<'_, PyDType>> {
265265
let decimal_type = DType::Decimal(DecimalDType::try_new(precision, scale)?, nullable.into());
266266
Ok(PyDType::init(py, decimal_type)?)
267267
}

vortex-python/src/dtype/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use crate::dtype::null::PyNullDType;
4747
use crate::dtype::primitive::PyPrimitiveDType;
4848
use crate::dtype::struct_::PyStructDType;
4949
use crate::dtype::utf8::PyUtf8DType;
50-
use crate::error::PyVortexError;
50+
use crate::error::PyVortexResult;
5151
use crate::install_module;
5252
use crate::python_repr::PythonRepr;
5353

@@ -154,11 +154,11 @@ impl PyDType {
154154

155155
#[pymethods]
156156
impl PyDType {
157-
fn to_arrow_type(&self, py: Python) -> Result<Py<PyAny>, PyVortexError> {
157+
fn to_arrow_type(&self, py: Python) -> PyVortexResult<Py<PyAny>> {
158158
Ok(self.0.to_arrow_dtype()?.to_pyarrow(py)?)
159159
}
160160

161-
fn to_arrow_schema(&self, py: Python) -> Result<Py<PyAny>, PyVortexError> {
161+
fn to_arrow_schema(&self, py: Python) -> PyVortexResult<Py<PyAny>> {
162162
Ok(self.0.to_arrow_schema()?.to_pyarrow(py)?)
163163
}
164164

0 commit comments

Comments
 (0)