Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Renamed ArrowError to Error #993

Merged
merged 2 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow-pyarrow-integration-testing/src/c_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn to_rust_iterator(ob: PyObject, py: Python) -> PyResult<Vec<PyObject>> {
ob.call_method1(py, "_export_to_c", (stream_ptr as Py_uintptr_t,))?;

let mut iter =
unsafe { ffi::ArrowArrayStreamReader::try_new(stream).map_err(PyO3ArrowError::from) }?;
unsafe { ffi::ArrowArrayStreamReader::try_new(stream).map_err(PyO3Error::from) }?;

let mut arrays = vec![];
while let Some(array) = unsafe { iter.next() } {
Expand Down
32 changes: 16 additions & 16 deletions arrow-pyarrow-integration-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,41 @@ use pyo3::ffi::Py_uintptr_t;
use pyo3::prelude::*;
use pyo3::wrap_pyfunction;

use arrow2::{array::Array, datatypes::Field, error::ArrowError, ffi};
use arrow2::{array::Array, datatypes::Field, error::Error, ffi};

/// an error that bridges ArrowError with a Python error
/// an error that bridges Error with a Python error
#[derive(Debug)]
enum PyO3ArrowError {
ArrowError(ArrowError),
enum PyO3Error {
Error(Error),
}

impl fmt::Display for PyO3ArrowError {
impl fmt::Display for PyO3Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
PyO3ArrowError::ArrowError(ref e) => e.fmt(f),
PyO3Error::Error(ref e) => e.fmt(f),
}
}
}

impl error::Error for PyO3ArrowError {
impl error::Error for PyO3Error {
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
match *self {
// The cause is the underlying implementation error type. Is implicitly
// cast to the trait object `&error::Error`. This works because the
// underlying type already implements the `Error` trait.
PyO3ArrowError::ArrowError(ref e) => Some(e),
PyO3Error::Error(ref e) => Some(e),
}
}
}

impl From<ArrowError> for PyO3ArrowError {
fn from(err: ArrowError) -> PyO3ArrowError {
PyO3ArrowError::ArrowError(err)
impl From<Error> for PyO3Error {
fn from(err: Error) -> PyO3Error {
PyO3Error::Error(err)
}
}

impl From<PyO3ArrowError> for PyErr {
fn from(err: PyO3ArrowError) -> PyErr {
impl From<PyO3Error> for PyErr {
fn from(err: PyO3Error) -> PyErr {
PyOSError::new_err(err.to_string())
}
}
Expand All @@ -66,9 +66,9 @@ fn to_rust_array(ob: PyObject, py: Python) -> PyResult<Arc<dyn Array>> {
(array_ptr as Py_uintptr_t, schema_ptr as Py_uintptr_t),
)?;

let field = unsafe { ffi::import_field_from_c(schema.as_ref()).map_err(PyO3ArrowError::from)? };
let field = unsafe { ffi::import_field_from_c(schema.as_ref()).map_err(PyO3Error::from)? };
let array =
unsafe { ffi::import_array_from_c(array, field.data_type).map_err(PyO3ArrowError::from)? };
unsafe { ffi::import_array_from_c(array, field.data_type).map_err(PyO3Error::from)? };

Ok(array.into())
}
Expand Down Expand Up @@ -110,7 +110,7 @@ fn to_rust_field(ob: PyObject, py: Python) -> PyResult<Field> {
// this changes the pointer's memory and is thus unsafe. In particular, `_export_to_c` can go out of bounds
ob.call_method1(py, "_export_to_c", (schema_ptr as Py_uintptr_t,))?;

let field = unsafe { ffi::import_field_from_c(schema.as_ref()).map_err(PyO3ArrowError::from)? };
let field = unsafe { ffi::import_field_from_c(schema.as_ref()).map_err(PyO3Error::from)? };

Ok(field)
}
Expand Down
4 changes: 2 additions & 2 deletions benches/write_json.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use criterion::{criterion_group, criterion_main, Criterion};

use arrow2::array::*;
use arrow2::error::ArrowError;
use arrow2::error::Error;
use arrow2::io::json::write;
use arrow2::util::bench_util::*;

fn write_array(array: Box<dyn Array>) -> Result<(), ArrowError> {
fn write_array(array: Box<dyn Array>) -> Result<(), Error> {
let mut writer = vec![];

let arrays = vec![Ok(array)].into_iter();
Expand Down
6 changes: 3 additions & 3 deletions examples/json_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::fs::File;

use arrow2::{
array::{Array, Int32Array},
error::ArrowError,
error::Error,
io::json::write,
};

fn write_array(path: &str, array: Box<dyn Array>) -> Result<(), ArrowError> {
fn write_array(path: &str, array: Box<dyn Array>) -> Result<(), Error> {
let mut writer = File::create(path)?;

let arrays = vec![Ok(array)].into_iter();
Expand All @@ -20,7 +20,7 @@ fn write_array(path: &str, array: Box<dyn Array>) -> Result<(), ArrowError> {
Ok(())
}

fn main() -> Result<(), ArrowError> {
fn main() -> Result<(), Error> {
use std::env;
let args: Vec<String> = env::args().collect();

Expand Down
4 changes: 2 additions & 2 deletions examples/parquet_write_parallel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use arrow2::{
array::*,
chunk::Chunk as AChunk,
datatypes::*,
error::{ArrowError, Result},
error::{Error, Result},
io::parquet::write::*,
};

Expand All @@ -30,7 +30,7 @@ impl Bla {

impl FallibleStreamingIterator for Bla {
type Item = CompressedPage;
type Error = ArrowError;
type Error = Error;

fn advance(&mut self) -> Result<()> {
self.current = self.columns.pop_front();
Expand Down
4 changes: 2 additions & 2 deletions integration-testing/src/bin/arrow-json-integration-test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use clap::Parser;
use arrow2::io::ipc::read;
use arrow2::io::ipc::write;
use arrow2::{
error::{ArrowError, Result},
error::{Error, Result},
io::json_integration::write as json_write,
};
use arrow_integration_testing::read_json_file;
Expand Down Expand Up @@ -123,7 +123,7 @@ fn validate(arrow_name: &str, json_name: &str, verbose: bool) -> Result<()> {

// compare schemas
if &json_file.schema != arrow_schema {
return Err(ArrowError::InvalidArgumentError(format!(
return Err(Error::InvalidArgumentError(format!(
"Schemas do not match. JSON: {:?}. Arrow: {:?}",
json_file.schema, arrow_schema
)));
Expand Down
10 changes: 5 additions & 5 deletions src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::DataType,
error::{ArrowError, Result},
error::{Error, Result},
};

use super::{
Expand Down Expand Up @@ -55,13 +55,13 @@ impl<O: Offset> BinaryArray<O> {
.as_ref()
.map_or(false, |validity| validity.len() != offsets.len() - 1)
{
return Err(ArrowError::oos(
return Err(Error::oos(
"validity mask length must match the number of values",
));
}

if data_type.to_physical_type() != Self::default_data_type().to_physical_type() {
return Err(ArrowError::oos(
return Err(Error::oos(
"BinaryArray can only be initialized with DataType::Binary or DataType::LargeBinary",
));
}
Expand Down Expand Up @@ -158,13 +158,13 @@ impl<O: Offset> BinaryArray<O> {
.as_ref()
.map_or(false, |validity| validity.len() != offsets.len() - 1)
{
return Err(ArrowError::oos(
return Err(Error::oos(
"validity mask length must match the number of values",
));
}

if data_type.to_physical_type() != Self::default_data_type().to_physical_type() {
return Err(ArrowError::oos(
return Err(Error::oos(
"BinaryArray can only be initialized with DataType::Binary or DataType::LargeBinary",
));
}
Expand Down
5 changes: 2 additions & 3 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
array::{specification::check_offsets, Array, MutableArray, Offset, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::DataType,
error::{ArrowError, Result},
error::{Error, Result},
trusted_len::TrustedLen,
};

Expand Down Expand Up @@ -426,8 +426,7 @@ impl<O: Offset, T: AsRef<[u8]>> TryPush<Option<T>> for MutableBinaryArray<O> {
Some(value) => {
let bytes = value.as_ref();

let size =
O::from_usize(self.values.len() + bytes.len()).ok_or(ArrowError::Overflow)?;
let size = O::from_usize(self.values.len() + bytes.len()).ok_or(Error::Overflow)?;

self.values.extend_from_slice(bytes);

Expand Down
8 changes: 4 additions & 4 deletions src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
bitmap::Bitmap,
datatypes::{DataType, PhysicalType},
error::ArrowError,
error::Error,
};
use either::Either;

Expand Down Expand Up @@ -35,18 +35,18 @@ impl BooleanArray {
data_type: DataType,
values: Bitmap,
validity: Option<Bitmap>,
) -> Result<Self, ArrowError> {
) -> Result<Self, Error> {
if validity
.as_ref()
.map_or(false, |validity| validity.len() != values.len())
{
return Err(ArrowError::oos(
return Err(Error::oos(
"validity mask length must match the number of values",
));
}

if data_type.to_physical_type() != PhysicalType::Boolean {
return Err(ArrowError::oos(
return Err(Error::oos(
"BooleanArray can only be initialized with a DataType whose physical type is Boolean",
));
}
Expand Down
4 changes: 2 additions & 2 deletions src/array/dictionary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
array::{primitive::MutablePrimitiveArray, Array, MutableArray, TryExtend, TryPush},
bitmap::MutableBitmap,
datatypes::DataType,
error::{ArrowError, Result},
error::{Error, Result},
};

use super::{DictionaryArray, DictionaryKey};
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<K: DictionaryKey, M: MutableArray> MutableDictionaryArray<K, M> {
Ok(false)
}
None => {
let key = K::from_usize(self.map.len()).ok_or(ArrowError::Overflow)?;
let key = K::from_usize(self.map.len()).ok_or(Error::Overflow)?;
self.map.insert(hash, key);
self.keys.push(Some(key));
Ok(true)
Expand Down
14 changes: 7 additions & 7 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bitmap::{Bitmap, MutableBitmap},
buffer::Buffer,
datatypes::DataType,
error::ArrowError,
error::Error,
};

use super::Array;
Expand Down Expand Up @@ -35,11 +35,11 @@ impl FixedSizeBinaryArray {
data_type: DataType,
values: Buffer<u8>,
validity: Option<Bitmap>,
) -> Result<Self, ArrowError> {
) -> Result<Self, Error> {
let size = Self::maybe_get_size(&data_type)?;

if values.len() % size != 0 {
return Err(ArrowError::oos(format!(
return Err(Error::oos(format!(
"values (of len {}) must be a multiple of size ({}) in FixedSizeBinaryArray.",
values.len(),
size
Expand All @@ -51,7 +51,7 @@ impl FixedSizeBinaryArray {
.as_ref()
.map_or(false, |validity| validity.len() != len)
{
return Err(ArrowError::oos(
return Err(Error::oos(
"validity mask length must be equal to the number of values divided by size",
));
}
Expand Down Expand Up @@ -216,10 +216,10 @@ impl FixedSizeBinaryArray {
}

impl FixedSizeBinaryArray {
pub(crate) fn maybe_get_size(data_type: &DataType) -> Result<usize, ArrowError> {
pub(crate) fn maybe_get_size(data_type: &DataType) -> Result<usize, Error> {
match data_type.to_logical_type() {
DataType::FixedSizeBinary(size) => Ok(*size),
_ => Err(ArrowError::oos(
_ => Err(Error::oos(
"FixedSizeBinaryArray expects DataType::FixedSizeBinary",
)),
}
Expand Down Expand Up @@ -269,7 +269,7 @@ impl FixedSizeBinaryArray {
pub fn try_from_iter<P: AsRef<[u8]>, I: IntoIterator<Item = Option<P>>>(
iter: I,
size: usize,
) -> Result<Self, ArrowError> {
) -> Result<Self, Error> {
MutableFixedSizeBinaryArray::try_from_iter(iter, size).map(|x| x.into())
}

Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
array::{Array, MutableArray},
bitmap::MutableBitmap,
datatypes::DataType,
error::{ArrowError, Result},
error::{Error, Result},
};

use super::{FixedSizeBinaryArray, FixedSizeBinaryValues};
Expand Down Expand Up @@ -82,7 +82,7 @@ impl MutableFixedSizeBinaryArray {
Some(bytes) => {
let bytes = bytes.as_ref();
if self.size != bytes.len() {
return Err(ArrowError::InvalidArgumentError(
return Err(Error::InvalidArgumentError(
"FixedSizeBinaryArray requires every item to be of its length".to_string(),
));
}
Expand Down
14 changes: 7 additions & 7 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::{
bitmap::Bitmap,
datatypes::{DataType, Field},
error::ArrowError,
error::Error,
};

use super::{new_empty_array, new_null_array, Array};
Expand Down Expand Up @@ -38,19 +38,19 @@ impl FixedSizeListArray {
data_type: DataType,
values: Arc<dyn Array>,
validity: Option<Bitmap>,
) -> Result<Self, ArrowError> {
) -> Result<Self, Error> {
let (child, size) = Self::try_child_and_size(&data_type)?;

let child_data_type = &child.data_type;
let values_data_type = values.data_type();
if child_data_type != values_data_type {
return Err(ArrowError::oos(
return Err(Error::oos(
format!("FixedSizeListArray's child's DataType must match. However, the expected DataType is {child_data_type:?} while it got {values_data_type:?}."),
));
}

if values.len() % size != 0 {
return Err(ArrowError::oos(format!(
return Err(Error::oos(format!(
"values (of len {}) must be a multiple of size ({}) in FixedSizeListArray.",
values.len(),
size
Expand All @@ -62,7 +62,7 @@ impl FixedSizeListArray {
.as_ref()
.map_or(false, |validity| validity.len() != len)
{
return Err(ArrowError::oos(
return Err(Error::oos(
"validity mask length must be equal to the number of values divided by size",
));
}
Expand Down Expand Up @@ -206,10 +206,10 @@ impl FixedSizeListArray {
}

impl FixedSizeListArray {
pub(crate) fn try_child_and_size(data_type: &DataType) -> Result<(&Field, usize), ArrowError> {
pub(crate) fn try_child_and_size(data_type: &DataType) -> Result<(&Field, usize), Error> {
match data_type.to_logical_type() {
DataType::FixedSizeList(child, size) => Ok((child.as_ref(), *size as usize)),
_ => Err(ArrowError::oos(
_ => Err(Error::oos(
"FixedSizeListArray expects DataType::FixedSizeList",
)),
}
Expand Down
Loading