Skip to content

Commit

Permalink
fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Oct 14, 2023
1 parent 37ef3a9 commit 8645f7d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion crates/nano-arrow/src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ impl FixedSizeBinaryArray {
pub(crate) fn maybe_get_size(data_type: &DataType) -> PolarsResult<usize> {
match data_type.to_logical_type() {
DataType::FixedSizeBinary(size) => {
polars_ensure!(*size == 0, ComputeError: "FixedSizeBinaryArray expects a positive size");
polars_ensure!(*size != 0, ComputeError: "FixedSizeBinaryArray expects a positive size");
Ok(*size)
},
_ => {
Expand Down
2 changes: 1 addition & 1 deletion crates/nano-arrow/src/array/growable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub fn make_growable<'a>(
match data_type.to_physical_type() {
Null => Box::new(null::GrowableNull::new(data_type.clone())),
Boolean => dyn_growable!(boolean::GrowableBoolean, arrays, use_validity, capacity),
Primitive(primitive) => with_match_primitive_type!(primitive, |$T| {
Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| {
dyn_growable!(primitive::GrowablePrimitive::<$T>, arrays, use_validity, capacity)
}),
Utf8 => dyn_growable!(utf8::GrowableUtf8::<i32>, arrays, use_validity, capacity),
Expand Down
4 changes: 2 additions & 2 deletions crates/nano-arrow/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ pub fn clone(array: &dyn Array) -> Box<dyn Array> {
match array.data_type().to_physical_type() {
Null => clone_dyn!(array, NullArray),
Boolean => clone_dyn!(array, BooleanArray),
Primitive(primitive) => with_match_primitive_type!(primitive, |$T| {
Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| {
clone_dyn!(array, PrimitiveArray<$T>)
}),
Binary => clone_dyn!(array, BinaryArray<i32>),
Expand Down Expand Up @@ -700,7 +700,7 @@ pub use union::UnionArray;
pub use utf8::{MutableUtf8Array, MutableUtf8ValuesArray, Utf8Array, Utf8ValuesIter};

pub(crate) use self::ffi::{offset_buffers_children_dictionary, FromFfi, ToFfi};
use crate::{match_integer_type, with_match_primitive_type};
use crate::{match_integer_type, with_match_primitive_type, with_match_primitive_type_full};

/// A trait describing the ability of a struct to create itself from a iterator.
/// This is similar to [`Extend`], but accepted the creation to error.
Expand Down
4 changes: 2 additions & 2 deletions crates/nano-arrow/src/ffi/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::buffer::{Buffer, Bytes, BytesAllocator};
use crate::datatypes::{DataType, PhysicalType};
use crate::ffi::schema::get_child;
use crate::types::NativeType;
use crate::{match_integer_type, with_match_primitive_type};
use crate::{match_integer_type, with_match_primitive_type_full};

/// Reads a valid `ffi` interface into a `Box<dyn Array>`
/// # Errors
Expand All @@ -22,7 +22,7 @@ pub unsafe fn try_from<A: ArrowArrayRef>(array: A) -> PolarsResult<Box<dyn Array
Ok(match array.data_type().to_physical_type() {
Null => Box::new(NullArray::try_from_ffi(array)?),
Boolean => Box::new(BooleanArray::try_from_ffi(array)?),
Primitive(primitive) => with_match_primitive_type!(primitive, |$T| {
Primitive(primitive) => with_match_primitive_type_full!(primitive, |$T| {
Box::new(PrimitiveArray::<$T>::try_from_ffi(array)?)
}),
Utf8 => Box::new(Utf8Array::<i32>::try_from_ffi(array)?),
Expand Down
23 changes: 23 additions & 0 deletions crates/nano-arrow/src/util/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ macro_rules! with_match_primitive_type {(
}
})}

#[macro_export]
macro_rules! with_match_primitive_type_full {(
$key_type:expr, | $_:tt $T:ident | $($body:tt)*
) => ({
macro_rules! __with_ty__ {( $_ $T:ident ) => ( $($body)* )}
use $crate::datatypes::PrimitiveType::*;
match $key_type {
Int8 => __with_ty__! { i8 },
Int16 => __with_ty__! { i16 },
Int32 => __with_ty__! { i32 },
Int64 => __with_ty__! { i64 },
UInt8 => __with_ty__! { u8 },
UInt16 => __with_ty__! { u16 },
UInt32 => __with_ty__! { u32 },
UInt64 => __with_ty__! { u64 },
Int128 => __with_ty__! { i128 },
Float32 => __with_ty__! { f32 },
Float64 => __with_ty__! { f64 },
_ => panic!("operator does not support primitive `{:?}`",
$key_type)
}
})}

#[macro_export]
macro_rules! match_integer_type {(
$key_type:expr, | $_:tt $T:ident | $($body:tt)*
Expand Down
2 changes: 1 addition & 1 deletion py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ def test_file_buffer() -> None:
f.write(b"1,2,3,4,5,6\n7,8,9,10,11,12")
f.seek(0)
# check if not fails on TryClone and Length impl in file.rs
with pytest.raises(pl.ArrowError):
with pytest.raises():
pl.read_parquet(f)


Expand Down

0 comments on commit 8645f7d

Please sign in to comment.