From 6b344bbcbf99c629823ae273683a13c8cb7a03c2 Mon Sep 17 00:00:00 2001 From: Jorge Leitao Date: Tue, 21 Dec 2021 06:06:47 +0000 Subject: [PATCH] Replaced Display by Debug (#694) --- examples/csv_read_async.rs | 2 +- examples/parquet_read.rs | 2 +- src/array/boolean/mod.rs | 4 +- src/array/dictionary/mod.rs | 2 +- src/array/fixed_size_binary/mod.rs | 4 +- src/array/fixed_size_list/mod.rs | 8 +-- src/array/list/mod.rs | 8 +-- src/array/mod.rs | 56 +++++++-------- src/array/null.rs | 4 +- src/array/primitive/display.rs | 6 +- src/array/primitive/mod.rs | 13 ++-- src/array/primitive/mutable.rs | 2 +- src/array/struct_/mod.rs | 6 +- src/array/union/mod.rs | 4 +- src/array/utf8/mod.rs | 2 +- src/compute/aggregate/min_max.rs | 4 +- src/compute/aggregate/sum.rs | 2 +- src/compute/if_then_else.rs | 2 +- src/compute/nullif.rs | 2 +- src/datatypes/field.rs | 6 -- src/datatypes/mod.rs | 6 -- src/datatypes/schema.rs | 13 ---- src/io/csv/write/serialize.rs | 2 +- src/io/parquet/write/dictionary.rs | 5 +- src/scalar/equal.rs | 2 +- src/scalar/primitive.rs | 2 +- tests/it/array/boolean/mod.rs | 2 +- tests/it/array/fixed_size_binary/mod.rs | 5 +- tests/it/array/list/mod.rs | 4 +- tests/it/array/primitive/mod.rs | 91 ++++++++++++++++--------- tests/it/array/union.rs | 4 +- tests/it/temporal_conversions.rs | 18 ++--- 32 files changed, 151 insertions(+), 142 deletions(-) diff --git a/examples/csv_read_async.rs b/examples/csv_read_async.rs index c893f59d809..7f89999e900 100644 --- a/examples/csv_read_async.rs +++ b/examples/csv_read_async.rs @@ -29,6 +29,6 @@ async fn main() -> Result<()> { 0, deserialize_column, )?; - println!("{}", batch.column(0)); + println!("{:?}", batch.column(0)); Ok(()) } diff --git a/examples/parquet_read.rs b/examples/parquet_read.rs index 8d37d83ec6c..5435ae34703 100644 --- a/examples/parquet_read.rs +++ b/examples/parquet_read.rs @@ -41,6 +41,6 @@ fn main() -> Result<()> { let row_group = args[3].parse::().unwrap(); let array = read_field(file_path, row_group, field)?; - println!("{}", array); + println!("{:?}", array); Ok(()) } diff --git a/src/array/boolean/mod.rs b/src/array/boolean/mod.rs index 79b1e959f10..1e6768e244f 100644 --- a/src/array/boolean/mod.rs +++ b/src/array/boolean/mod.rs @@ -15,7 +15,7 @@ pub use mutable::*; /// The Arrow's equivalent to an immutable `Vec>`, but with `1/16` of its size. /// Cloning and slicing this struct is `O(1)`. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct BooleanArray { data_type: DataType, values: Bitmap, @@ -168,7 +168,7 @@ impl Array for BooleanArray { } } -impl std::fmt::Display for BooleanArray { +impl std::fmt::Debug for BooleanArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { display_fmt(self.iter(), "BooleanArray", f, false) } diff --git a/src/array/dictionary/mod.rs b/src/array/dictionary/mod.rs index 6d186b6bce1..d3f06fb2b24 100644 --- a/src/array/dictionary/mod.rs +++ b/src/array/dictionary/mod.rs @@ -208,7 +208,7 @@ where fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let display = get_value_display(self); let new_lines = false; - let head = &format!("{}", self.data_type()); + let head = &format!("{:?}", self.data_type()); let iter = self.iter().enumerate().map(|(i, x)| x.map(|_| display(i))); display_fmt(iter, head, f, new_lines) } diff --git a/src/array/fixed_size_binary/mod.rs b/src/array/fixed_size_binary/mod.rs index e2eaaf08f0a..d68c484d45c 100644 --- a/src/array/fixed_size_binary/mod.rs +++ b/src/array/fixed_size_binary/mod.rs @@ -9,7 +9,7 @@ pub use mutable::*; /// The Arrow's equivalent to an immutable `Vec>`. /// Cloning and slicing this struct is `O(1)`. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct FixedSizeBinaryArray { size: usize, // this is redundant with `data_type`, but useful to not have to deconstruct the data_type. data_type: DataType, @@ -205,7 +205,7 @@ impl Array for FixedSizeBinaryArray { } } -impl std::fmt::Display for FixedSizeBinaryArray { +impl std::fmt::Debug for FixedSizeBinaryArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let iter = self.iter().map(|x| x.map(|x| format!("{:?}", x))); display_fmt(iter, "FixedSizeBinaryArray", f, false) diff --git a/src/array/fixed_size_list/mod.rs b/src/array/fixed_size_list/mod.rs index f8ff1036ab0..79554f54910 100644 --- a/src/array/fixed_size_list/mod.rs +++ b/src/array/fixed_size_list/mod.rs @@ -5,7 +5,7 @@ use crate::{ datatypes::{DataType, Field}, }; -use super::{display_fmt, new_empty_array, new_null_array, Array}; +use super::{debug_fmt, new_empty_array, new_null_array, Array}; mod ffi; mod iterator; @@ -15,7 +15,7 @@ pub use mutable::*; /// The Arrow's equivalent to an immutable `Vec>` where `T` is an Arrow type. /// Cloning and slicing this struct is `O(1)`. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct FixedSizeListArray { size: usize, // this is redundant with `data_type`, but useful to not have to deconstruct the data_type. data_type: DataType, @@ -196,8 +196,8 @@ impl Array for FixedSizeListArray { } } -impl std::fmt::Display for FixedSizeListArray { +impl std::fmt::Debug for FixedSizeListArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - display_fmt(self.iter(), "FixedSizeListArray", f, true) + debug_fmt(self.iter(), "FixedSizeListArray", f, true) } } diff --git a/src/array/list/mod.rs b/src/array/list/mod.rs index 11e6fd7592b..36608ab17ab 100644 --- a/src/array/list/mod.rs +++ b/src/array/list/mod.rs @@ -7,7 +7,7 @@ use crate::{ }; use super::{ - display_fmt, new_empty_array, + debug_fmt, new_empty_array, specification::{check_offsets, Offset}, Array, }; @@ -19,7 +19,7 @@ mod mutable; pub use mutable::*; /// An [`Array`] semantically equivalent to `Vec>>>` with Arrow's in-memory. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct ListArray { data_type: DataType, offsets: Buffer, @@ -241,13 +241,13 @@ impl Array for ListArray { } } -impl std::fmt::Display for ListArray { +impl std::fmt::Debug for ListArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let head = if O::is_large() { "LargeListArray" } else { "ListArray" }; - display_fmt(self.iter(), head, f, true) + debug_fmt(self.iter(), head, f, true) } } diff --git a/src/array/mod.rs b/src/array/mod.rs index 317543087a1..730336c47b6 100644 --- a/src/array/mod.rs +++ b/src/array/mod.rs @@ -18,7 +18,6 @@ //! Most arrays contain a [`MutableArray`] counterpart that is neither clonable nor slicable, but //! can be operated in-place. use std::any::Any; -use std::fmt::Display; use crate::error::Result; use crate::types::{days_ms, months_days_ns}; @@ -29,7 +28,7 @@ use crate::{ /// A trait representing an immutable Arrow array. Arrow arrays are trait objects /// that are infalibly downcasted to concrete types according to the [`Array::data_type`]. -pub trait Array: std::fmt::Debug + Send + Sync { +pub trait Array: Send + Sync { /// Convert to trait object. fn as_any(&self) -> &dyn Any; @@ -214,7 +213,7 @@ macro_rules! with_match_primitive_type {( } })} -impl Display for dyn Array { +impl std::fmt::Debug for dyn Array + '_ { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use crate::datatypes::PhysicalType::*; match self.data_type().to_physical_type() { @@ -394,31 +393,34 @@ pub trait TryPush { } fn display_helper>>(iter: I) -> Vec { - let iterator = iter.into_iter(); - let len = iterator.size_hint().0; - if len <= 100 { - iterator - .map(|x| match x { - Some(x) => x.to_string(), - None => "".to_string(), - }) - .collect::>() + iter.into_iter() + .map(|x| match x { + Some(x) => x.to_string(), + None => "None".to_string(), + }) + .collect::>() +} + +fn debug_helper>>(iter: I) -> Vec { + iter.into_iter() + .map(|x| match x { + Some(x) => format!("{:?}", x), + None => "None".to_string(), + }) + .collect::>() +} + +fn debug_fmt>>( + iter: I, + head: &str, + f: &mut std::fmt::Formatter<'_>, + new_lines: bool, +) -> std::fmt::Result { + let result = debug_helper(iter); + if new_lines { + write!(f, "{}[\n{}\n]", head, result.join(",\n")) } else { - iterator - .enumerate() - .filter_map(|(i, x)| { - if i == 5 { - Some(format!("...({})...", len - 10)) - } else if i < 5 || i > (len - 5) { - Some(match x { - Some(x) => x.to_string(), - None => "".to_string(), - }) - } else { - None - } - }) - .collect::>() + write!(f, "{}[{}]", head, result.join(", ")) } } diff --git a/src/array/null.rs b/src/array/null.rs index 6037bd68cec..9c09b8ce705 100644 --- a/src/array/null.rs +++ b/src/array/null.rs @@ -7,7 +7,7 @@ use crate::{ }; /// The concrete [`Array`] of [`DataType::Null`]. -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct NullArray { data_type: DataType, length: usize, @@ -74,7 +74,7 @@ impl Array for NullArray { } } -impl std::fmt::Display for NullArray { +impl std::fmt::Debug for NullArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "NullArray({})", self.len()) } diff --git a/src/array/primitive/display.rs b/src/array/primitive/display.rs index 911eb258798..c0d33fc4d01 100644 --- a/src/array/primitive/display.rs +++ b/src/array/primitive/display.rs @@ -1,14 +1,14 @@ use crate::types::NativeType; use super::super::display::get_value_display; -use super::super::{display_fmt, Array}; +use super::super::display_fmt; use super::PrimitiveArray; -impl std::fmt::Display for PrimitiveArray { +impl std::fmt::Debug for PrimitiveArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let display = get_value_display(self); let new_lines = false; - let head = &format!("{}", self.data_type()); + let head = &format!("{:?}", self.data_type()); let iter = self.iter().enumerate().map(|(i, x)| x.map(|_| display(i))); display_fmt(iter, head, f, new_lines) } diff --git a/src/array/primitive/mod.rs b/src/array/primitive/mod.rs index a84e5e60e7e..c2d57b88f7a 100644 --- a/src/array/primitive/mod.rs +++ b/src/array/primitive/mod.rs @@ -30,7 +30,7 @@ pub use mutable::*; /// assert_eq!(array.validity(), Some(&Bitmap::from([true, false, true]))); /// # } /// ``` -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct PrimitiveArray { data_type: DataType, values: Buffer, @@ -61,7 +61,7 @@ impl PrimitiveArray { pub fn from_data(data_type: DataType, values: Buffer, validity: Option) -> Self { if !T::is_valid(&data_type) { Err(ArrowError::InvalidArgumentError(format!( - "Type {} does not support logical type {}", + "Type {} does not support logical type {:?}", std::any::type_name::(), data_type ))) @@ -135,6 +135,11 @@ impl PrimitiveArray { self.validity.as_ref() } + #[inline] + fn data_type(&self) -> &DataType { + &self.data_type + } + /// The values [`Buffer`]. /// Values on null slots are undetermined (they can be anything). #[inline] @@ -166,7 +171,7 @@ impl PrimitiveArray { pub fn to(self, data_type: DataType) -> Self { if !T::is_valid(&data_type) { Err(ArrowError::InvalidArgumentError(format!( - "Type {} does not support logical type {}", + "Type {} does not support logical type {:?}", std::any::type_name::(), data_type ))) @@ -193,7 +198,7 @@ impl Array for PrimitiveArray { #[inline] fn data_type(&self) -> &DataType { - &self.data_type + self.data_type() } fn validity(&self) -> Option<&Bitmap> { diff --git a/src/array/primitive/mutable.rs b/src/array/primitive/mutable.rs index ac5613b754d..4f78c93c87f 100644 --- a/src/array/primitive/mutable.rs +++ b/src/array/primitive/mutable.rs @@ -62,7 +62,7 @@ impl MutablePrimitiveArray { ) -> Self { if !T::is_valid(&data_type) { Err(ArrowError::InvalidArgumentError(format!( - "Type {} does not support logical type {}", + "Type {} does not support logical type {:?}", std::any::type_name::(), data_type ))) diff --git a/src/array/struct_/mod.rs b/src/array/struct_/mod.rs index c54be876809..a528568e088 100644 --- a/src/array/struct_/mod.rs +++ b/src/array/struct_/mod.rs @@ -27,7 +27,7 @@ mod iterator; /// /// let array = StructArray::from_data(DataType::Struct(fields), vec![boolean, int], None); /// ``` -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct StructArray { data_type: DataType, values: Vec>, @@ -214,11 +214,11 @@ impl Array for StructArray { } } -impl std::fmt::Display for StructArray { +impl std::fmt::Debug for StructArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { writeln!(f, "StructArray{{")?; for (field, column) in self.fields().iter().zip(self.values()) { - writeln!(f, "{}: {},", field.name(), column)?; + writeln!(f, "{}: {:?},", field.name(), column)?; } write!(f, "}}") } diff --git a/src/array/union/mod.rs b/src/array/union/mod.rs index a3facb19ded..5ef0ff9d86d 100644 --- a/src/array/union/mod.rs +++ b/src/array/union/mod.rs @@ -23,7 +23,7 @@ type FieldEntry = (usize, Arc); // let field = field.as_any().downcast to correct type; // let value = field.value(offset); // ``` -#[derive(Debug, Clone)] +#[derive(Clone)] pub struct UnionArray { types: Buffer, // None represents when there is no typeid @@ -274,7 +274,7 @@ impl UnionArray { } } -impl std::fmt::Display for UnionArray { +impl std::fmt::Debug for UnionArray { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { let display = get_value_display(self); let new_lines = false; diff --git a/src/array/utf8/mod.rs b/src/array/utf8/mod.rs index 2a49f51e7ed..d70649015f8 100644 --- a/src/array/utf8/mod.rs +++ b/src/array/utf8/mod.rs @@ -261,7 +261,7 @@ impl Array for Utf8Array { impl std::fmt::Display for Utf8Array { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - display_fmt(self.iter(), &format!("{}", self.data_type()), f, false) + display_fmt(self.iter(), &format!("{:?}", self.data_type()), f, false) } } diff --git a/src/compute/aggregate/min_max.rs b/src/compute/aggregate/min_max.rs index 4e6adc7390f..6d0638f92da 100644 --- a/src/compute/aggregate/min_max.rs +++ b/src/compute/aggregate/min_max.rs @@ -394,7 +394,7 @@ pub fn max(array: &dyn Array) -> Result> { } _ => { return Err(ArrowError::InvalidArgumentError(format!( - "The `max` operator does not support type `{}`", + "The `max` operator does not support type `{:?}`", array.data_type(), ))) } @@ -435,7 +435,7 @@ pub fn min(array: &dyn Array) -> Result> { } _ => { return Err(ArrowError::InvalidArgumentError(format!( - "The `max` operator does not support type `{}`", + "The `max` operator does not support type `{:?}`", array.data_type(), ))) } diff --git a/src/compute/aggregate/sum.rs b/src/compute/aggregate/sum.rs index dae1ad85734..578ea6bd42d 100644 --- a/src/compute/aggregate/sum.rs +++ b/src/compute/aggregate/sum.rs @@ -168,7 +168,7 @@ pub fn sum(array: &dyn Array) -> Result> { DataType::Float64 => dyn_sum!(f64, array), _ => { return Err(ArrowError::InvalidArgumentError(format!( - "The `sum` operator does not support type `{}`", + "The `sum` operator does not support type `{:?}`", array.data_type(), ))) } diff --git a/src/compute/if_then_else.rs b/src/compute/if_then_else.rs index 4b44b9f7cf6..371901c7b70 100644 --- a/src/compute/if_then_else.rs +++ b/src/compute/if_then_else.rs @@ -30,7 +30,7 @@ pub fn if_then_else( ) -> Result> { if lhs.data_type() != rhs.data_type() { return Err(ArrowError::InvalidArgumentError(format!( - "If then else requires the arguments to have the same datatypes ({} != {})", + "If then else requires the arguments to have the same datatypes ({:?} != {:?})", lhs.data_type(), rhs.data_type() ))); diff --git a/src/compute/nullif.rs b/src/compute/nullif.rs index 891ace88053..ffeec517d86 100644 --- a/src/compute/nullif.rs +++ b/src/compute/nullif.rs @@ -165,7 +165,7 @@ pub fn nullif(lhs: &dyn Array, rhs: &dyn Array) -> Result> { ) .map(|x| Box::new(x) as Box), other => Err(ArrowError::NotYetImplemented(format!( - "Nullif is not implemented for logical datatype {}", + "Nullif is not implemented for logical datatype {:?}", other ))), } diff --git a/src/datatypes/field.rs b/src/datatypes/field.rs index 1febcf1d3e4..9526bb912a8 100644 --- a/src/datatypes/field.rs +++ b/src/datatypes/field.rs @@ -292,9 +292,3 @@ impl Field { Ok(()) } } - -impl std::fmt::Display for Field { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} diff --git a/src/datatypes/mod.rs b/src/datatypes/mod.rs index 8ab7ef579f8..9e7aa002d9e 100644 --- a/src/datatypes/mod.rs +++ b/src/datatypes/mod.rs @@ -138,12 +138,6 @@ pub enum DataType { Extension(String, Box, Option), } -impl std::fmt::Display for DataType { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{:?}", self) - } -} - /// Mode of [`DataType::Union`] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum UnionMode { diff --git a/src/datatypes/schema.rs b/src/datatypes/schema.rs index bb8540655b6..9372c084240 100644 --- a/src/datatypes/schema.rs +++ b/src/datatypes/schema.rs @@ -194,16 +194,3 @@ impl Schema { .find(|&(_, c)| c.name() == name) } } - -impl std::fmt::Display for Schema { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - f.write_str( - &self - .fields - .iter() - .map(|c| c.to_string()) - .collect::>() - .join(", "), - ) - } -} diff --git a/src/io/csv/write/serialize.rs b/src/io/csv/write/serialize.rs index 959c1f56b1b..37c8b97f4fc 100644 --- a/src/io/csv/write/serialize.rs +++ b/src/io/csv/write/serialize.rs @@ -398,7 +398,7 @@ pub fn new_serializer<'a>( panic!("only dictionary with string values are supported by csv writer") } }, - dt => panic!("data type: {} not supported by csv writer", dt), + dt => panic!("data type: {:?} not supported by csv writer", dt), }) } diff --git a/src/io/parquet/write/dictionary.rs b/src/io/parquet/write/dictionary.rs index d5df74e5bd6..cad4ea78abf 100644 --- a/src/io/parquet/write/dictionary.rs +++ b/src/io/parquet/write/dictionary.rs @@ -123,10 +123,7 @@ pub fn array_to_pages( descriptor: ColumnDescriptor, options: WriteOptions, encoding: Encoding, -) -> Result>> -where - PrimitiveArray: std::fmt::Display, -{ +) -> Result>> { match encoding { Encoding::PlainDictionary | Encoding::RleDictionary => { // write DictPage diff --git a/src/scalar/equal.rs b/src/scalar/equal.rs index 519f49656ed..6c1ea3a1d56 100644 --- a/src/scalar/equal.rs +++ b/src/scalar/equal.rs @@ -135,6 +135,6 @@ fn equal(lhs: &dyn Scalar, rhs: &dyn Scalar) -> bool { let rhs = rhs.as_any().downcast_ref::().unwrap(); lhs == rhs } - other => unimplemented!("{}", other), + other => unimplemented!("{:?}", other), } } diff --git a/src/scalar/primitive.rs b/src/scalar/primitive.rs index 2d2c827fdf7..d001b51a47c 100644 --- a/src/scalar/primitive.rs +++ b/src/scalar/primitive.rs @@ -20,7 +20,7 @@ impl PrimitiveScalar { pub fn new(data_type: DataType, value: Option) -> Self { if !T::is_valid(&data_type) { Err(ArrowError::InvalidArgumentError(format!( - "Type {} does not support logical type {}", + "Type {} does not support logical type {:?}", std::any::type_name::(), data_type ))) diff --git a/tests/it/array/boolean/mod.rs b/tests/it/array/boolean/mod.rs index 84decd124f8..38d67b0c785 100644 --- a/tests/it/array/boolean/mod.rs +++ b/tests/it/array/boolean/mod.rs @@ -47,7 +47,7 @@ fn with_validity() { #[test] fn display() { let array = BooleanArray::from([Some(true), None, Some(false)]); - assert_eq!(format!("{}", array), "BooleanArray[true, , false]"); + assert_eq!(format!("{:?}", array), "BooleanArray[true, None, false]"); } #[test] diff --git a/tests/it/array/fixed_size_binary/mod.rs b/tests/it/array/fixed_size_binary/mod.rs index 79a1bf21311..24976493c61 100644 --- a/tests/it/array/fixed_size_binary/mod.rs +++ b/tests/it/array/fixed_size_binary/mod.rs @@ -37,7 +37,10 @@ fn display() { values, Some(Bitmap::from([true, false, true])), ); - assert_eq!(format!("{}", a), "FixedSizeBinaryArray[[1, 2], , [5, 6]]"); + assert_eq!( + format!("{:?}", a), + "FixedSizeBinaryArray[[1, 2], None, [5, 6]]" + ); } #[test] diff --git a/tests/it/array/list/mod.rs b/tests/it/array/list/mod.rs index b3717465d95..e46c628809d 100644 --- a/tests/it/array/list/mod.rs +++ b/tests/it/array/list/mod.rs @@ -20,7 +20,7 @@ fn display() { ); assert_eq!( - format!("{}", array), + format!("{:?}", array), "ListArray[\nInt32[1, 2],\nInt32[],\nInt32[3],\nInt32[4, 5]\n]" ); } @@ -62,5 +62,5 @@ fn test_nested_display() { ListArray::::from_data(data_type, Buffer::from([0, 2, 5, 6]), Arc::new(array), None); let expected = "ListArray[\nListArray[\nInt32[1, 2],\nInt32[3, 4]\n],\nListArray[\nInt32[5, 6, 7],\nInt32[],\nInt32[8]\n],\nListArray[\nInt32[9, 10]\n]\n]"; - assert_eq!(format!("{}", nested), expected); + assert_eq!(format!("{:?}", nested), expected); } diff --git a/tests/it/array/primitive/mod.rs b/tests/it/array/primitive/mod.rs index 7e3a0532c3f..2677afc105a 100644 --- a/tests/it/array/primitive/mod.rs +++ b/tests/it/array/primitive/mod.rs @@ -78,19 +78,25 @@ fn from() { #[test] fn display_int32() { let array = Int32Array::from(&[Some(1), None, Some(2)]); - assert_eq!(format!("{}", array), "Int32[1, , 2]"); + assert_eq!(format!("{:?}", array), "Int32[1, None, 2]"); } #[test] fn display_date32() { let array = Int32Array::from(&[Some(1), None, Some(2)]).to(DataType::Date32); - assert_eq!(format!("{}", array), "Date32[1970-01-02, , 1970-01-03]"); + assert_eq!( + format!("{:?}", array), + "Date32[1970-01-02, None, 1970-01-03]" + ); } #[test] fn display_time32s() { let array = Int32Array::from(&[Some(1), None, Some(2)]).to(DataType::Time32(TimeUnit::Second)); - assert_eq!(format!("{}", array), "Time32(Second)[00:00:01, , 00:00:02]"); + assert_eq!( + format!("{:?}", array), + "Time32(Second)[00:00:01, None, 00:00:02]" + ); } #[test] @@ -98,8 +104,8 @@ fn display_time32ms() { let array = Int32Array::from(&[Some(1), None, Some(2)]).to(DataType::Time32(TimeUnit::Millisecond)); assert_eq!( - format!("{}", array), - "Time32(Millisecond)[00:00:00.001, , 00:00:00.002]" + format!("{:?}", array), + "Time32(Millisecond)[00:00:00.001, None, 00:00:00.002]" ); } @@ -107,19 +113,22 @@ fn display_time32ms() { fn display_interval_d() { let array = Int32Array::from(&[Some(1), None, Some(2)]).to(DataType::Interval(IntervalUnit::YearMonth)); - assert_eq!(format!("{}", array), "Interval(YearMonth)[1m, , 2m]"); + assert_eq!(format!("{:?}", array), "Interval(YearMonth)[1m, None, 2m]"); } #[test] fn display_int64() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Int64); - assert_eq!(format!("{}", array), "Int64[1, , 2]"); + assert_eq!(format!("{:?}", array), "Int64[1, None, 2]"); } #[test] fn display_date64() { let array = Int64Array::from(&[Some(1), None, Some(86400000)]).to(DataType::Date64); - assert_eq!(format!("{}", array), "Date64[1970-01-01, , 1970-01-02]"); + assert_eq!( + format!("{:?}", array), + "Date64[1970-01-01, None, 1970-01-02]" + ); } #[test] @@ -127,8 +136,8 @@ fn display_time64us() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Time64(TimeUnit::Microsecond)); assert_eq!( - format!("{}", array), - "Time64(Microsecond)[00:00:00.000001, , 00:00:00.000002]" + format!("{:?}", array), + "Time64(Microsecond)[00:00:00.000001, None, 00:00:00.000002]" ); } @@ -137,8 +146,8 @@ fn display_time64ns() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Time64(TimeUnit::Nanosecond)); assert_eq!( - format!("{}", array), - "Time64(Nanosecond)[00:00:00.000000001, , 00:00:00.000000002]" + format!("{:?}", array), + "Time64(Nanosecond)[00:00:00.000000001, None, 00:00:00.000000002]" ); } @@ -147,8 +156,8 @@ fn display_timestamp_s() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Timestamp(TimeUnit::Second, None)); assert_eq!( - format!("{}", array), - "Timestamp(Second, None)[1970-01-01 00:00:01, , 1970-01-01 00:00:02]" + format!("{:?}", array), + "Timestamp(Second, None)[1970-01-01 00:00:01, None, 1970-01-01 00:00:02]" ); } @@ -157,8 +166,8 @@ fn display_timestamp_ms() { let array = Int64Array::from(&[Some(1), None, Some(2)]) .to(DataType::Timestamp(TimeUnit::Millisecond, None)); assert_eq!( - format!("{}", array), - "Timestamp(Millisecond, None)[1970-01-01 00:00:00.001, , 1970-01-01 00:00:00.002]" + format!("{:?}", array), + "Timestamp(Millisecond, None)[1970-01-01 00:00:00.001, None, 1970-01-01 00:00:00.002]" ); } @@ -167,8 +176,8 @@ fn display_timestamp_us() { let array = Int64Array::from(&[Some(1), None, Some(2)]) .to(DataType::Timestamp(TimeUnit::Microsecond, None)); assert_eq!( - format!("{}", array), - "Timestamp(Microsecond, None)[1970-01-01 00:00:00.000001, , 1970-01-01 00:00:00.000002]" + format!("{:?}", array), + "Timestamp(Microsecond, None)[1970-01-01 00:00:00.000001, None, 1970-01-01 00:00:00.000002]" ); } @@ -177,8 +186,8 @@ fn display_timestamp_ns() { let array = Int64Array::from(&[Some(1), None, Some(2)]) .to(DataType::Timestamp(TimeUnit::Nanosecond, None)); assert_eq!( - format!("{}", array), - "Timestamp(Nanosecond, None)[1970-01-01 00:00:00.000000001, , 1970-01-01 00:00:00.000000002]" + format!("{:?}", array), + "Timestamp(Nanosecond, None)[1970-01-01 00:00:00.000000001, None, 1970-01-01 00:00:00.000000002]" ); } @@ -189,8 +198,8 @@ fn display_timestamp_tz_ns() { Some("+02:00".to_string()), )); assert_eq!( - format!("{}", array), - "Timestamp(Nanosecond, Some(\"+02:00\"))[1970-01-01 02:00:00.000000001 +02:00, , 1970-01-01 02:00:00.000000002 +02:00]" + format!("{:?}", array), + "Timestamp(Nanosecond, Some(\"+02:00\"))[1970-01-01 02:00:00.000000001 +02:00, None, 1970-01-01 02:00:00.000000002 +02:00]" ); } @@ -198,50 +207,68 @@ fn display_timestamp_tz_ns() { fn display_duration_ms() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Duration(TimeUnit::Millisecond)); - assert_eq!(format!("{}", array), "Duration(Millisecond)[1ms, , 2ms]"); + assert_eq!( + format!("{:?}", array), + "Duration(Millisecond)[1ms, None, 2ms]" + ); } #[test] fn display_duration_s() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Duration(TimeUnit::Second)); - assert_eq!(format!("{}", array), "Duration(Second)[1s, , 2s]"); + assert_eq!(format!("{:?}", array), "Duration(Second)[1s, None, 2s]"); } #[test] fn display_duration_us() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Duration(TimeUnit::Microsecond)); - assert_eq!(format!("{}", array), "Duration(Microsecond)[1us, , 2us]"); + assert_eq!( + format!("{:?}", array), + "Duration(Microsecond)[1us, None, 2us]" + ); } #[test] fn display_duration_ns() { let array = Int64Array::from(&[Some(1), None, Some(2)]).to(DataType::Duration(TimeUnit::Nanosecond)); - assert_eq!(format!("{}", array), "Duration(Nanosecond)[1ns, , 2ns]"); + assert_eq!( + format!("{:?}", array), + "Duration(Nanosecond)[1ns, None, 2ns]" + ); } #[test] fn display_decimal() { let array = Int128Array::from(&[Some(12345), None, Some(23456)]).to(DataType::Decimal(5, 2)); - assert_eq!(format!("{}", array), "Decimal(5, 2)[123.45, , 234.56]"); + assert_eq!( + format!("{:?}", array), + "Decimal(5, 2)[123.45, None, 234.56]" + ); } #[test] fn display_decimal1() { let array = Int128Array::from(&[Some(12345), None, Some(23456)]).to(DataType::Decimal(5, 1)); - assert_eq!(format!("{}", array), "Decimal(5, 1)[1234.5, , 2345.6]"); + assert_eq!( + format!("{:?}", array), + "Decimal(5, 1)[1234.5, None, 2345.6]" + ); } #[test] fn display_interval_days_ms() { let array = DaysMsArray::from(&[Some(days_ms::new(1, 1)), None, Some(days_ms::new(2, 2))]); - assert_eq!(format!("{}", array), "Interval(DayTime)[1d1ms, , 2d2ms]"); + assert_eq!( + format!("{:?}", array), + "Interval(DayTime)[1d1ms, None, 2d2ms]" + ); } #[test] -fn display_months_days_ns() { +fn debug_months_days_ns() { let data = &[ Some(months_days_ns::new(1, 1, 2)), None, @@ -251,8 +278,8 @@ fn display_months_days_ns() { let array = MonthsDaysNsArray::from(&data); assert_eq!( - format!("{}", array), - "Interval(MonthDayNano)[1m1d2ns, , 2m3d3ns]" + format!("{:?}", array), + "Interval(MonthDayNano)[1m1d2ns, None, 2m3d3ns]" ); } diff --git a/tests/it/array/union.rs b/tests/it/array/union.rs index 9ed49a272b6..6ef19408343 100644 --- a/tests/it/array/union.rs +++ b/tests/it/array/union.rs @@ -3,7 +3,7 @@ use std::sync::Arc; use arrow2::{array::*, buffer::Buffer, datatypes::*, error::Result}; #[test] -fn display() -> Result<()> { +fn debug() -> Result<()> { let fields = vec![ Field::new("a", DataType::Int32, true), Field::new("b", DataType::Utf8, true), @@ -17,7 +17,7 @@ fn display() -> Result<()> { let array = UnionArray::from_data(data_type, types, fields, None); - assert_eq!(format!("{}", array), "UnionArray[1, , c]"); + assert_eq!(format!("{:?}", array), "UnionArray[1, None, c]"); Ok(()) } diff --git a/tests/it/temporal_conversions.rs b/tests/it/temporal_conversions.rs index 672c4f04203..7f8e7313882 100644 --- a/tests/it/temporal_conversions.rs +++ b/tests/it/temporal_conversions.rs @@ -5,7 +5,7 @@ use arrow2::types::months_days_ns; #[test] fn naive() { - let expected = "Timestamp(Nanosecond, None)[1996-12-19 16:39:57, 1996-12-19 13:39:57, ]"; + let expected = "Timestamp(Nanosecond, None)[1996-12-19 16:39:57, 1996-12-19 13:39:57, None]"; let fmt = "%Y-%m-%dT%H:%M:%S:z"; let array = Utf8Array::::from_slice(&[ "1996-12-19T16:39:57-02:00", @@ -13,7 +13,7 @@ fn naive() { "1996-12-19 13:39:57-03:00", // missing T ]); let r = temporal_conversions::utf8_to_naive_timestamp_ns(&array, fmt); - assert_eq!(format!("{}", r), expected); + assert_eq!(format!("{:?}", r), expected); let fmt = "%Y-%m-%dT%H:%M:%S"; // no tz info let array = Utf8Array::::from_slice(&[ @@ -22,12 +22,12 @@ fn naive() { "1996-12-19 13:39:57-03:00", // missing T ]); let r = temporal_conversions::utf8_to_naive_timestamp_ns(&array, fmt); - assert_eq!(format!("{}", r), expected); + assert_eq!(format!("{:?}", r), expected); } #[test] fn naive_no_tz() { - let expected = "Timestamp(Nanosecond, None)[1996-12-19 16:39:57, 1996-12-19 13:39:57, ]"; + let expected = "Timestamp(Nanosecond, None)[1996-12-19 16:39:57, 1996-12-19 13:39:57, None]"; let fmt = "%Y-%m-%dT%H:%M:%S"; // no tz info let array = Utf8Array::::from_slice(&[ "1996-12-19T16:39:57", @@ -35,14 +35,14 @@ fn naive_no_tz() { "1996-12-19 13:39:57", // missing T ]); let r = temporal_conversions::utf8_to_naive_timestamp_ns(&array, fmt); - assert_eq!(format!("{}", r), expected); + assert_eq!(format!("{:?}", r), expected); } #[test] fn tz_aware() { let tz = "-02:00".to_string(); let expected = - "Timestamp(Nanosecond, Some(\"-02:00\"))[1996-12-19 16:39:57 -02:00, 1996-12-19 17:39:57 -02:00, ]"; + "Timestamp(Nanosecond, Some(\"-02:00\"))[1996-12-19 16:39:57 -02:00, 1996-12-19 17:39:57 -02:00, None]"; let fmt = "%Y-%m-%dT%H:%M:%S%.f%:z"; let array = Utf8Array::::from_slice(&[ "1996-12-19T16:39:57.0-02:00", @@ -50,13 +50,13 @@ fn tz_aware() { "1996-12-19 13:39:57.0-03:00", ]); let r = temporal_conversions::utf8_to_timestamp_ns(&array, fmt, tz).unwrap(); - assert_eq!(format!("{}", r), expected); + assert_eq!(format!("{:?}", r), expected); } #[test] fn tz_aware_no_timezone() { let tz = "-02:00".to_string(); - let expected = "Timestamp(Nanosecond, Some(\"-02:00\"))[, , ]"; + let expected = "Timestamp(Nanosecond, Some(\"-02:00\"))[None, None, None]"; let fmt = "%Y-%m-%dT%H:%M:%S%.f"; let array = Utf8Array::::from_slice(&[ "1996-12-19T16:39:57.0", @@ -64,7 +64,7 @@ fn tz_aware_no_timezone() { "1996-12-19 13:39:57.0", ]); let r = temporal_conversions::utf8_to_timestamp_ns(&array, fmt, tz).unwrap(); - assert_eq!(format!("{}", r), expected); + assert_eq!(format!("{:?}", r), expected); } #[test]