Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Jan 12, 2024
1 parent 664d021 commit 40541b4
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 58 deletions.
5 changes: 4 additions & 1 deletion tests/it/array/growable/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ fn some_values() -> (DataType, Vec<Box<dyn Array>>) {
Field::new("key", DataType::Utf8, true),
Field::new("val", DataType::Int32, true),
];
(DataType::Struct(std::sync::Arc::new(fields)), vec![strings, ints])
(
DataType::Struct(std::sync::Arc::new(fields)),
vec![strings, ints],
)
}

#[test]
Expand Down
5 changes: 4 additions & 1 deletion tests/it/array/growable/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ fn some_values() -> (DataType, Vec<Box<dyn Array>>) {
Field::new("f1", DataType::Utf8, true),
Field::new("f2", DataType::Int32, true),
];
(DataType::Struct(std::sync::Arc::new(fields)), vec![strings, ints])
(
DataType::Struct(std::sync::Arc::new(fields)),
vec![strings, ints],
)
}

#[test]
Expand Down
6 changes: 4 additions & 2 deletions tests/it/array/growable/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,10 @@ fn dense() -> Result<()> {

#[test]
fn complex_dense() -> Result<()> {
let fixed_size_type =
DataType::FixedSizeList(std::sync::Arc::new(Field::new("i", DataType::UInt16, true)), 3);
let fixed_size_type = DataType::FixedSizeList(
std::sync::Arc::new(Field::new("i", DataType::UInt16, true)),
3,
);

let fields = vec![
Field::new("a", DataType::Int32, true),
Expand Down
6 changes: 4 additions & 2 deletions tests/it/compute/aggregate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ fn utf8() {

#[test]
fn fixed_size_list() {
let data_type =
DataType::FixedSizeList(std::sync::Arc::new(Field::new("elem", DataType::Float32, false)), 3);
let data_type = DataType::FixedSizeList(
std::sync::Arc::new(Field::new("elem", DataType::Float32, false)),
3,
);
let values = Box::new(Float32Array::from_slice([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]));
let a = FixedSizeListArray::new(data_type, values, None);
assert_eq!(6 * std::mem::size_of::<f32>(), estimated_bytes_size(&a));
Expand Down
115 changes: 70 additions & 45 deletions tests/it/compute/arithmetics/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,47 @@ use arrow2::types::months_days_ns;

#[test]
fn test_adding_timestamp() {
let timestamp =
PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let timestamp = PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)])
.to(DataType::Duration(TimeUnit::Second));

let result = add_duration(&timestamp, &duration);
let expected =
PrimitiveArray::from([Some(100010i64), Some(200020i64), None, Some(300030i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected = PrimitiveArray::from([Some(100010i64), Some(200020i64), None, Some(300030i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

assert_eq!(result, expected);

let duration = PrimitiveScalar::from(Some(10i64)).to(DataType::Duration(TimeUnit::Second));

let result = add_duration_scalar(&timestamp, &duration);
let expected =
PrimitiveArray::from([Some(100010i64), Some(200010i64), None, Some(300010i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected = PrimitiveArray::from([Some(100010i64), Some(200010i64), None, Some(300010i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));
assert_eq!(result, expected);
}

#[test]
fn test_adding_duration_different_scale() {
let timestamp =
PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected =
PrimitiveArray::from([Some(100010i64), Some(200020i64), None, Some(300030i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let timestamp = PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));
let expected = PrimitiveArray::from([Some(100010i64), Some(200020i64), None, Some(300030i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

// Testing duration in milliseconds
let duration = PrimitiveArray::from([Some(10_000i64), Some(20_000i64), None, Some(30_000i64)])
Expand Down Expand Up @@ -69,20 +74,29 @@ fn test_adding_duration_different_scale() {
#[test]
fn test_adding_subtract_timestamps_scale() {
let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to(
DataType::Timestamp(TimeUnit::Millisecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
DataType::Timestamp(
TimeUnit::Millisecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
),
);
let duration = PrimitiveArray::from([Some(1i64), Some(2i64), None, Some(3i64)])
.to(DataType::Duration(TimeUnit::Second));

let expected = PrimitiveArray::from([Some(1_010i64), Some(2_020i64), None, Some(3_030i64)]).to(
DataType::Timestamp(TimeUnit::Millisecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
DataType::Timestamp(
TimeUnit::Millisecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
),
);

let result = add_duration(&timestamp, &duration);
assert_eq!(result, expected);

let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to(
DataType::Timestamp(TimeUnit::Nanosecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
DataType::Timestamp(
TimeUnit::Nanosecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
),
);
let duration = PrimitiveArray::from([Some(1i64), Some(2i64), None, Some(3i64)])
.to(DataType::Duration(TimeUnit::Second));
Expand All @@ -104,33 +118,37 @@ fn test_adding_subtract_timestamps_scale() {

#[test]
fn test_subtract_timestamp() {
let timestamp =
PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let timestamp = PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

let duration = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)])
.to(DataType::Duration(TimeUnit::Second));

let result = subtract_duration(&timestamp, &duration);
let expected =
PrimitiveArray::from([Some(99990i64), Some(199980i64), None, Some(299970i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected = PrimitiveArray::from([Some(99990i64), Some(199980i64), None, Some(299970i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

assert_eq!(result, expected);
}

#[test]
fn test_subtracting_duration_different_scale() {
let timestamp =
PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected =
PrimitiveArray::from([Some(99990i64), Some(199980i64), None, Some(299970i64)]).to(
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let timestamp = PrimitiveArray::from([Some(100000i64), Some(200000i64), None, Some(300000i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));
let expected = PrimitiveArray::from([Some(99990i64), Some(199980i64), None, Some(299970i64)])
.to(DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

// Testing duration in milliseconds
let duration = PrimitiveArray::from([Some(10_000i64), Some(20_000i64), None, Some(30_000i64)])
Expand Down Expand Up @@ -158,21 +176,28 @@ fn test_subtracting_duration_different_scale() {
#[test]
fn test_subtracting_subtract_timestamps_scale() {
let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to(
DataType::Timestamp(TimeUnit::Millisecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
DataType::Timestamp(
TimeUnit::Millisecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
),
);
let duration = PrimitiveArray::from([Some(1i64), Some(2i64), None, Some(3i64)])
.to(DataType::Duration(TimeUnit::Second));

let expected =
PrimitiveArray::from([Some(-990i64), Some(-1_980i64), None, Some(-2_970i64)]).to(
DataType::Timestamp(TimeUnit::Millisecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
);
let expected = PrimitiveArray::from([Some(-990i64), Some(-1_980i64), None, Some(-2_970i64)])
.to(DataType::Timestamp(
TimeUnit::Millisecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
));

let result = subtract_duration(&timestamp, &duration);
assert_eq!(result, expected);

let timestamp = PrimitiveArray::from([Some(10i64), Some(20i64), None, Some(30i64)]).to(
DataType::Timestamp(TimeUnit::Nanosecond, Some(std::sync::Arc::new("America/New_york".to_string()))),
DataType::Timestamp(
TimeUnit::Nanosecond,
Some(std::sync::Arc::new("America/New_york".to_string())),
),
);
let duration = PrimitiveArray::from([Some(1i64), Some(2i64), None, Some(3i64)])
.to(DataType::Duration(TimeUnit::Second));
Expand Down
5 changes: 4 additions & 1 deletion tests/it/io/csv/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ fn deserialize_timestamp() -> Result<()> {
let input = vec!["1996-12-19T16:34:57-02:00", "1996-12-19T16:34:58-02:00"];
let input = input.join("\n");

let data_type = DataType::Timestamp(TimeUnit::Millisecond, Some(std::sync::Arc::new("-01:00".to_string())));
let data_type = DataType::Timestamp(
TimeUnit::Millisecond,
Some(std::sync::Arc::new("-01:00".to_string())),
);

let expected = Int64Array::from([Some(851020497000), Some(851020498000)]).to(data_type.clone());

Expand Down
11 changes: 9 additions & 2 deletions tests/it/io/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ fn write_timestamp_second_with_tz() {
];
check_datetime!(
i64,
DataType::Timestamp(TimeUnit::Second, Some(std::sync::Arc::new("UTC".to_string()))),
DataType::Timestamp(
TimeUnit::Second,
Some(std::sync::Arc::new("UTC".to_string()))
),
11111111,
expected
);
Expand Down Expand Up @@ -327,7 +330,11 @@ fn write_struct() -> Result<()> {

let validity = Some(Bitmap::from(&[true, false, true]));

let array = StructArray::new(DataType::Struct(std::sync::Arc::new(fields)), values, validity);
let array = StructArray::new(
DataType::Struct(std::sync::Arc::new(fields)),
values,
validity,
);

let columns = Chunk::new(vec![&array as &dyn Array]);

Expand Down
10 changes: 8 additions & 2 deletions tests/it/scalar/fixed_size_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ use arrow2::{
#[allow(clippy::eq_op)]
#[test]
fn equal() {
let dt = DataType::FixedSizeList(std::sync::Arc::new(Field::new("a", DataType::Boolean, true)), 2);
let dt = DataType::FixedSizeList(
std::sync::Arc::new(Field::new("a", DataType::Boolean, true)),
2,
);
let a = FixedSizeListScalar::new(
dt.clone(),
Some(BooleanArray::from_slice([true, false]).boxed()),
Expand All @@ -26,7 +29,10 @@ fn equal() {

#[test]
fn basics() {
let dt = DataType::FixedSizeList(std::sync::Arc::new(Field::new("a", DataType::Boolean, true)), 2);
let dt = DataType::FixedSizeList(
std::sync::Arc::new(Field::new("a", DataType::Boolean, true)),
2,
);
let a = FixedSizeListScalar::new(
dt.clone(),
Some(BooleanArray::from_slice([true, false]).boxed()),
Expand Down
12 changes: 10 additions & 2 deletions tests/it/scalar/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ use arrow2::{
#[allow(clippy::eq_op)]
#[test]
fn equal() {
let dt = DataType::List(std::sync::Arc::new(Field::new("a", DataType::Boolean, true)));
let dt = DataType::List(std::sync::Arc::new(Field::new(
"a",
DataType::Boolean,
true,
)));
let a = ListScalar::<i32>::new(
dt.clone(),
Some(BooleanArray::from_slice([true, false]).boxed()),
Expand All @@ -23,7 +27,11 @@ fn equal() {

#[test]
fn basics() {
let dt = DataType::List(std::sync::Arc::new(Field::new("a", DataType::Boolean, true)));
let dt = DataType::List(std::sync::Arc::new(Field::new(
"a",
DataType::Boolean,
true,
)));
let a = ListScalar::<i32>::new(
dt.clone(),
Some(BooleanArray::from_slice([true, false]).boxed()),
Expand Down

0 comments on commit 40541b4

Please sign in to comment.