Skip to content

Commit

Permalink
[Minor] Fix clippy errors with new rust version (1.56) and float form…
Browse files Browse the repository at this point in the history
…atting with nightly (#845)

* Clippy fixes

* Test formatting fixes

* Test formatting fixes

* Fixup
  • Loading branch information
Dandandan authored and alamb committed Oct 23, 2021
1 parent 9e52269 commit 313ea65
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 73 deletions.
108 changes: 58 additions & 50 deletions arrow/src/compute/kernels/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2340,35 +2340,41 @@ mod tests {
let f64_array: ArrayRef = Arc::new(Float64Array::from(f64_values));

let f64_expected = vec![
"-9223372036854776000.0",
"-2147483648.0",
"-32768.0",
"-128.0",
"0.0",
"255.0",
"65535.0",
"4294967295.0",
"18446744073709552000.0",
-9223372036854776000.0,
-2147483648.0,
-32768.0,
-128.0,
0.0,
255.0,
65535.0,
4294967295.0,
18446744073709552000.0,
];
assert_eq!(
f64_expected,
get_cast_values::<Float64Type>(&f64_array, &DataType::Float64)
.iter()
.map(|i| i.parse::<f64>().unwrap())
.collect::<Vec<f64>>()
);

let f32_expected = vec![
"-9223372000000000000.0",
"-2147483600.0",
"-32768.0",
"-128.0",
"0.0",
"255.0",
"65535.0",
"4294967300.0",
"18446744000000000000.0",
-9223372000000000000.0,
-2147483600.0,
-32768.0,
-128.0,
0.0,
255.0,
65535.0,
4294967300.0,
18446744000000000000.0,
];
assert_eq!(
f32_expected,
get_cast_values::<Float32Type>(&f64_array, &DataType::Float32)
.iter()
.map(|i| i.parse::<f32>().unwrap())
.collect::<Vec<f32>>()
);

let i64_expected = vec![
Expand Down Expand Up @@ -2615,28 +2621,24 @@ mod tests {
];
let u64_array: ArrayRef = Arc::new(UInt64Array::from(u64_values));

let f64_expected = vec![
"0.0",
"255.0",
"65535.0",
"4294967295.0",
"18446744073709552000.0",
];
let f64_expected =
vec![0.0, 255.0, 65535.0, 4294967295.0, 18446744073709552000.0];
assert_eq!(
f64_expected,
get_cast_values::<Float64Type>(&u64_array, &DataType::Float64)
.iter()
.map(|i| i.parse::<f64>().unwrap())
.collect::<Vec<f64>>()
);

let f32_expected = vec![
"0.0",
"255.0",
"65535.0",
"4294967300.0",
"18446744000000000000.0",
];
let f32_expected =
vec![0.0, 255.0, 65535.0, 4294967300.0, 18446744000000000000.0];
assert_eq!(
f32_expected,
get_cast_values::<Float32Type>(&u64_array, &DataType::Float32)
.iter()
.map(|i| i.parse::<f32>().unwrap())
.collect::<Vec<f32>>()
);

let i64_expected = vec!["0", "255", "65535", "4294967295", "null"];
Expand Down Expand Up @@ -2908,35 +2910,41 @@ mod tests {
let i64_array: ArrayRef = Arc::new(Int64Array::from(i64_values));

let f64_expected = vec![
"-9223372036854776000.0",
"-2147483648.0",
"-32768.0",
"-128.0",
"0.0",
"127.0",
"32767.0",
"2147483647.0",
"9223372036854776000.0",
-9223372036854776000.0,
-2147483648.0,
-32768.0,
-128.0,
0.0,
127.0,
32767.0,
2147483647.0,
9223372036854776000.0,
];
assert_eq!(
f64_expected,
get_cast_values::<Float64Type>(&i64_array, &DataType::Float64)
.iter()
.map(|i| i.parse::<f64>().unwrap())
.collect::<Vec<f64>>()
);

let f32_expected = vec![
"-9223372000000000000.0",
"-2147483600.0",
"-32768.0",
"-128.0",
"0.0",
"127.0",
"32767.0",
"2147483600.0",
"9223372000000000000.0",
-9223372000000000000.0,
-2147483600.0,
-32768.0,
-128.0,
0.0,
127.0,
32767.0,
2147483600.0,
9223372000000000000.0,
];
assert_eq!(
f32_expected,
get_cast_values::<Float32Type>(&i64_array, &DataType::Float32)
.iter()
.map(|i| i.parse::<f32>().unwrap())
.collect::<Vec<f32>>()
);

let i64_expected = vec![
Expand Down
13 changes: 1 addition & 12 deletions arrow/src/ipc/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,18 +347,7 @@ fn create_list_array(
buffers: &[Buffer],
child_array: ArrayRef,
) -> ArrayRef {
if let DataType::List(_) = *data_type {
let null_count = field_node.null_count() as usize;
let mut builder = ArrayData::builder(data_type.clone())
.len(field_node.length() as usize)
.buffers(buffers[1..2].to_vec())
.offset(0)
.child_data(vec![child_array.data().clone()]);
if null_count > 0 {
builder = builder.null_bit_buffer(buffers[0].clone())
}
make_array(unsafe { builder.build_unchecked() })
} else if let DataType::LargeList(_) = *data_type {
if let DataType::List(_) | DataType::LargeList(_) = *data_type {
let null_count = field_node.null_count() as usize;
let mut builder = ArrayData::builder(data_type.clone())
.len(field_node.length() as usize)
Expand Down
17 changes: 6 additions & 11 deletions parquet/src/schema/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,19 +371,14 @@ impl<'a> Parser<'a> {
"Failed to parse scale for DECIMAL type",
)?;
assert_token(self.tokenizer.next(), ")")?;
logical = Some(LogicalType::DECIMAL(DecimalType {
scale,
precision,
}));
converted = ConvertedType::from(logical.clone());
} else {
scale = 0;
logical = Some(LogicalType::DECIMAL(DecimalType {
scale,
precision,
}));
converted = ConvertedType::from(logical.clone());
scale = 0
}
logical = Some(LogicalType::DECIMAL(DecimalType {
scale,
precision,
}));
converted = ConvertedType::from(logical.clone());
}
}
LogicalType::TIME(_) => {
Expand Down

0 comments on commit 313ea65

Please sign in to comment.