Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix tests in arrow-cast.
  • Loading branch information
Rachelint committed Jul 7, 2024
commit fc975d39d4ef3a1f62e3dfe057e19f7fceb8fe19
18 changes: 9 additions & 9 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4314,8 +4314,8 @@ mod tests {
IntervalUnit::YearMonth,
IntervalYearMonthArray,
vec![
Some("1 years 1 mons 0 days 0 hours 0 mins 0.00 secs"),
Some("2 years 7 mons 0 days 0 hours 0 mins 0.00 secs"),
Some("1 years 1 mons"),
Some("2 years 7 mons"),
None,
None,
None,
Expand All @@ -4338,12 +4338,12 @@ mod tests {
IntervalUnit::DayTime,
IntervalDayTimeArray,
vec![
Some("0 years 0 mons 390 days 0 hours 0 mins 0.000 secs"),
Some("0 years 0 mons 930 days 0 hours 0 mins 0.000 secs"),
Some("0 years 0 mons 30 days 0 hours 0 mins 0.000 secs"),
Some("390 days"),
Some("930 days"),
Some("30 days"),
None,
None,
]
]
);
}

Expand All @@ -4366,15 +4366,15 @@ mod tests {
IntervalUnit::MonthDayNano,
IntervalMonthDayNanoArray,
vec![
Some("13 mons 1 days "),
Some("13 mons 1 days"),
None,
Some("31 mons 35 days 0.001400000 secs"),
Some("3 days "),
Some("3 days"),
Some("8.000000000 secs"),
None,
Some("1 days 29.800000000 secs"),
Some("3 mons 1.000000000 secs"),
Some("8 mins "),
Some("8 mins"),
Some("63 mons 9 days 19 hours 9 mins 2.222000000 secs"),
None,
]
Expand Down
34 changes: 18 additions & 16 deletions arrow-cast/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
//! record batch pretty printing.
//!
//! [`pretty`]: crate::pretty
use std::f32::consts::E;
use std::fmt::{Display, Formatter, Write};
use std::ops::Range;

Expand All @@ -36,7 +35,6 @@ use arrow_buffer::ArrowNativeType;
use arrow_schema::*;
use chrono::{NaiveDate, NaiveDateTime, SecondsFormat, TimeZone, Utc};
use lexical_core::FormattedSize;
use num::Signed;

type TimeFormat<'a> = Option<&'a str>;

Expand Down Expand Up @@ -667,7 +665,7 @@ impl<'a> DisplayIndex for &'a PrimitiveArray<IntervalDayTimeType> {
let mut first_part = true;

if value.days != 0 {
write!(f, "{} days ", value.days)?;
write!(f, "{} days", value.days)?;
first_part = false;
}

Expand All @@ -690,16 +688,16 @@ impl<'a> DisplayIndex for &'a PrimitiveArray<IntervalMonthDayNanoType> {
let mut first_part = true;

if value.months != 0 {
write!(f, "{} mons ", value.months)?;
write!(f, "{} mons", value.months)?;
first_part = false;
}

if value.days != 0 {
if first_part {
write!(f, "{} days ", value.days)?;
write!(f, "{} days", value.days)?;
first_part = false;
} else {
write!(f, " {} days ", value.days)?;
write!(f, " {} days", value.days)?;
}
}

Expand All @@ -722,6 +720,8 @@ struct NanosecondsFormatter {

impl Display for NanosecondsFormatter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut first_part = self.first_part;

let secs = self.nanoseconds / 1_000_000_000;
let mins = secs / 60;
let hours = mins / 60;
Expand All @@ -732,18 +732,18 @@ impl Display for NanosecondsFormatter {
let nanoseconds = self.nanoseconds % 1_000_000_000;

if hours != 0 {
if self.first_part {
if first_part {
write!(f, "{} hours", hours)?;
self.first_part = false;
first_part = false;
} else {
write!(f, " {} hours", hours)?;
}
}

if mins != 0 {
if self.first_part {
if first_part {
write!(f, "{} mins", mins)?;
self.first_part = false;
first_part = false;
} else {
write!(f, " {} mins", mins)?;
}
Expand All @@ -752,7 +752,7 @@ impl Display for NanosecondsFormatter {
if secs != 0 || nanoseconds != 0 {
let secs_sign = if secs < 0 || nanoseconds < 0 { "-" } else { "" };

if self.first_part {
if first_part {
write!(
f,
"{}{}.{:09} secs",
Expand Down Expand Up @@ -782,6 +782,8 @@ struct MillisecondsFormatter {

impl Display for MillisecondsFormatter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let mut first_part = self.first_part;

let secs = self.milliseconds / 1_000;
let mins = secs / 60;
let hours = mins / 60;
Expand All @@ -792,20 +794,20 @@ impl Display for MillisecondsFormatter {
let milliseconds = self.milliseconds % 1_000;

if hours != 0 {
if self.first_part {
if first_part {
write!(f, "{} hours", hours,)?;
first_part = false;
} else {
write!(f, " {} hours", hours,)?;
self.first_part = false;
}
}

if mins != 0 {
if self.first_part {
if first_part {
write!(f, "{} mins", mins,)?;
first_part = false;
} else {
write!(f, " {} mins", mins,)?;
self.first_part = false;
}
}

Expand All @@ -816,7 +818,7 @@ impl Display for MillisecondsFormatter {
""
};

if self.first_part {
if first_part {
write!(
f,
"{}{}.{:03} secs",
Expand Down