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

make thousands crate optional with apply feature #1453

Merged
merged 2 commits into from
Dec 6, 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
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ sysinfo = "0.29"
tabwriter = "1.3"
tempfile = "3"
test-data-generation = { version = "0.3", optional = true }
thousands = "0.2"
thousands = { version = "0.2", optional = true }
threadpool = "1.8"
titlecase = { version = "2", optional = true }
tokio = "1"
Expand Down Expand Up @@ -255,6 +255,7 @@ apply = [
"hashbrown",
"qsv_currency",
"strsim",
"thousands",
"titlecase",
"vader_sentiment",
"whatlang",
Expand Down
10 changes: 3 additions & 7 deletions src/cmd/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
};

if args.flag_human_readable {
use thousands::Separable;
use indicatif::HumanCount;

if args.flag_width {
woutinfo!(
"{};{}",
count.separate_with_commas(),
width.separate_with_commas()
);
woutinfo!("{};{}", HumanCount(count as u64), HumanCount(width as u64));

Check warning

Code scanning / clippy

casting to the same type is unnecessary (`u64` -> `u64`)

casting to the same type is unnecessary (`u64` -> `u64`)
} else {
woutinfo!("{}", count.separate_with_commas());
woutinfo!("{}", HumanCount(count as u64));

Check warning

Code scanning / clippy

casting to the same type is unnecessary (`u64` -> `u64`)

casting to the same type is unnecessary (`u64` -> `u64`)
}
} else if args.flag_width {
woutinfo!("{count};{width}");
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
}

if args.flag_human_readable {
use thousands::Separable;
use indicatif::HumanCount;

eprintln!("{}", dupe_count.separate_with_commas());
eprintln!("{}", HumanCount(dupe_count as u64));
} else {
eprintln!("{dupe_count}");
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/extdedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ use std::{
io::{self, stdin, stdout, BufRead, Write},
};

use indicatif::HumanCount;
use serde::Deserialize;
use sysinfo::{System, SystemExt};
use thousands::Separable;

use crate::{config, odhtcache, util, CliResult};

Expand Down Expand Up @@ -159,7 +159,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
eprintln!(
"{}",
if args.flag_human_readable {
dupes_count.separate_with_commas()
HumanCount(dupes_count).to_string()
} else {
dupes_count.to_string()
}
Expand Down
22 changes: 9 additions & 13 deletions src/cmd/sniff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ use bytes::Bytes;
use file_format::FileFormat;
use futures::executor::block_on;
use futures_util::StreamExt;
use indicatif::HumanCount;
#[cfg(any(feature = "feature_capable", feature = "lite"))]
use indicatif::{HumanBytes, HumanCount, ProgressBar, ProgressDrawTarget, ProgressStyle};
use indicatif::{HumanBytes, ProgressBar, ProgressDrawTarget, ProgressStyle};
use qsv_sniffer::{DatePreference, SampleSize, Sniffer};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_json::json;
use tabwriter::TabWriter;
use tempfile::NamedTempFile;
use thousands::Separable;
use url::Url;

use crate::{
Expand Down Expand Up @@ -207,7 +207,7 @@ impl fmt::Display for SniffStruct {
writeln!(
f,
"Preamble Rows: {}",
self.preamble_rows.separate_with_commas()
HumanCount(self.preamble_rows as u64)
)?;
writeln!(f, "Quote Char: {}", self.quote_char)?;
writeln!(f, "Flexible: {}", self.flexible)?;
Expand All @@ -217,30 +217,26 @@ impl fmt::Display for SniffStruct {
writeln!(
f,
"Retrieved Size (bytes): {}",
self.retrieved_size.separate_with_commas()
HumanCount(self.retrieved_size as u64)
)?;
writeln!(
f,
"File Size (bytes): {}",
self.file_size.separate_with_commas()
HumanCount(self.file_size as u64)
)?;
writeln!(
f,
"Sampled Records: {}",
self.sampled_records.separate_with_commas()
HumanCount(self.sampled_records as u64)
)?;
writeln!(f, "Estimated: {}", self.estimated)?;
writeln!(
f,
"Num Records: {}",
self.num_records.separate_with_commas()
)?;
writeln!(f, "Num Records: {}", HumanCount(self.num_records as u64))?;
writeln!(
f,
"Avg Record Len (bytes): {}",
self.avg_record_len.separate_with_commas()
HumanCount(self.avg_record_len as u64)
)?;
writeln!(f, "Num Fields: {}", self.num_fields.separate_with_commas())?;
writeln!(f, "Num Fields: {}", HumanCount(self.num_fields as u64))?;
writeln!(f, "Stats Types: {}", self.stats_types)?;
writeln!(f, "Fields:")?;

Expand Down
6 changes: 3 additions & 3 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ impl Config {
fs::File::open(&idx_path_work)?
} else if data_fsize >= NO_INDEX_WARNING_FILESIZE {
// warn user that the CSV file is large and not indexed
use thousands::Separable;
use indicatif::HumanCount;

warn!(
"The {} MB CSV file is larger than the {} MB \
NO_INDEX_WARNING_FILESIZE threshold. Consider creating an \
index file as it will make qsv commands much faster.",
(data_fsize * 100).separate_with_commas(),
(NO_INDEX_WARNING_FILESIZE * 100).separate_with_commas()
HumanCount(data_fsize * 100),
HumanCount(NO_INDEX_WARNING_FILESIZE * 100)
);
return Ok(None);
} else {
Expand Down
4 changes: 2 additions & 2 deletions tests/test_count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ fn prop_count_len(
cmd.arg("in.csv");

if human_readable {
use thousands::Separable;
use indicatif::HumanCount;

let got_count: String = wrk.stdout(&mut cmd);
let expected_count_commas = expected_count.separate_with_commas();
let expected_count_commas = HumanCount(expected_count as u64).to_string();

rassert_eq!(got_count, expected_count_commas)
} else {
Expand Down