diff --git a/crates/nano-arrow/src/array/fixed_size_binary/mod.rs b/crates/nano-arrow/src/array/fixed_size_binary/mod.rs index 9b17ac3d7155..710c87d1b7bf 100644 --- a/crates/nano-arrow/src/array/fixed_size_binary/mod.rs +++ b/crates/nano-arrow/src/array/fixed_size_binary/mod.rs @@ -206,7 +206,7 @@ impl FixedSizeBinaryArray { pub(crate) fn maybe_get_size(data_type: &DataType) -> PolarsResult { 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) }, _ => { diff --git a/crates/nano-arrow/src/array/growable/mod.rs b/crates/nano-arrow/src/array/growable/mod.rs index a3fe4b739451..a896a430e9cd 100644 --- a/crates/nano-arrow/src/array/growable/mod.rs +++ b/crates/nano-arrow/src/array/growable/mod.rs @@ -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::, arrays, use_validity, capacity), diff --git a/crates/nano-arrow/src/array/mod.rs b/crates/nano-arrow/src/array/mod.rs index b38be5fba38e..390b2667f8f0 100644 --- a/crates/nano-arrow/src/array/mod.rs +++ b/crates/nano-arrow/src/array/mod.rs @@ -628,7 +628,7 @@ pub fn clone(array: &dyn Array) -> Box { 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), @@ -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. diff --git a/crates/nano-arrow/src/ffi/array.rs b/crates/nano-arrow/src/ffi/array.rs index 1658d119daeb..80b0efd54525 100644 --- a/crates/nano-arrow/src/ffi/array.rs +++ b/crates/nano-arrow/src/ffi/array.rs @@ -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` /// # Errors @@ -22,7 +22,7 @@ pub unsafe fn try_from(array: A) -> PolarsResult 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::::try_from_ffi(array)?), diff --git a/crates/nano-arrow/src/util/macros.rs b/crates/nano-arrow/src/util/macros.rs index 9df8b4c427fd..e1274bbc441f 100644 --- a/crates/nano-arrow/src/util/macros.rs +++ b/crates/nano-arrow/src/util/macros.rs @@ -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)* diff --git a/py-polars/tests/unit/dataframe/test_df.py b/py-polars/tests/unit/dataframe/test_df.py index ceadea5a8d87..79ec6a2de06c 100644 --- a/py-polars/tests/unit/dataframe/test_df.py +++ b/py-polars/tests/unit/dataframe/test_df.py @@ -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)