Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excel: minor performance tweaks #1446

Merged
merged 1 commit into from
Dec 3, 2023
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
Binary file modified resources/test/excel-xlsx.xlsx
Binary file not shown.
12 changes: 7 additions & 5 deletions src/cmd/excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,17 +624,19 @@
cell_date_flag = true;
},
DataType::Error(ref e) => record.push_field(&format!("{e:?}")),
DataType::Bool(ref b) => record.push_field(&b.to_string()),
DataType::DateTimeIso(ref dt) => record.push_field(&dt.to_string()),
DataType::DurationIso(ref d) => record.push_field(&d.to_string()),
DataType::Bool(ref b) => {
record.push_field(if *b { "true" } else { "false" })
},
DataType::DateTimeIso(ref dt) => record.push_field(&dt),
Dismissed Show dismissed Hide dismissed
DataType::DurationIso(ref d) => record.push_field(&d),
Dismissed Show dismissed Hide dismissed
DataType::Duration(ref d) => record.push_field(ryu_buffer.format(*d)),
};

#[allow(clippy::cast_precision_loss)]
if float_flag {
if cell_date_flag {
// its a date, so convert it
work_date = if float_val.fract() > 0.0 {
work_date = if float_val.fract() > f64::EPSILON {
// if it has a fractional part, then its a datetime
if let Some(dt) = cell.as_datetime() {
if date_format.is_empty() {
Expand Down Expand Up @@ -680,7 +682,7 @@
// its not a date, so just push the ryu-formatted float value if its
// not an integer or the candidate
// integer is too big or too small to be an i64
} else if float_val.fract().abs() > 0.0
} else if float_val.fract().abs() > f64::EPSILON
|| float_val > i64::MAX as f64
|| float_val < i64::MIN as f64
{
Expand Down
21 changes: 21 additions & 0 deletions tests/test_excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,27 @@ fn excel_date_xlsx_date_format() {
assert_eq!(got, expected);
}

#[test]
fn excel_xlsx_data_types() {
let wrk = Workdir::new("excel_xlsx_data_types");

let xlsx_file = wrk.load_test_file("excel-xlsx.xlsx");

let mut cmd = wrk.command("excel");
cmd.arg("--sheet").arg("data types").arg(xlsx_file);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![
svec!["int", "float", "bool", "date", "duration", "string", "emojis", "foreign"],
svec!["1", "1.1", "true", "2001-09-11", "0.4305555555555556", "The", "The", "敏捷的棕色狐狸在森林里奔跑"],
svec!["2", "1.32434354545454", "false", "2023-10-07", "0.989849537037037", "quick", "🍔", "Franz jagt im komplett verwahrlosten Taxi quer durch Bayern"],
svec!["3", "0.423546456564534", "1", "1941-12-07", "1.2815162037037038", "brown", "is", "Le rusé goupil franchit d'un bond le chien somnolent."],
svec!["4", "-54545.6565756785", "0", "2001-09-11 08:30:00", "0.9791666666666666", "fox", "💩", "El rápido zorro marrón"],
svec!["5", "-5446563454.43546", "true", "1945-08-06 08:15:00", "0.0004629629629629629", "jumped", "🙀", "いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす"]
];
assert_eq!(got, expected);
}

#[test]
fn excel_date_xlsx() {
let wrk = Workdir::new("excel_date_xls");
Expand Down
Loading