Skip to content

Commit

Permalink
Enable clippy::float_equality_without_abs lint (#1305)
Browse files Browse the repository at this point in the history
  • Loading branch information
gsserge authored Feb 14, 2022
1 parent 6ee1fda commit 41fedad
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 31 deletions.
10 changes: 5 additions & 5 deletions arrow/src/array/array_union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ mod tests {
.downcast_ref::<Float64Array>()
.unwrap()
.value(0);
assert!(10.0 - value < f64::EPSILON);
assert_eq!(10.0, value);

let slot = array.value(4);
let value = slot
Expand Down Expand Up @@ -771,7 +771,7 @@ mod tests {
let slot = slot.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(slot.len(), 1);
let value = slot.value(0);
assert!(value - 3_f64 < f64::EPSILON);
assert_eq!(value, 3_f64);
}
2 => {
let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
Expand All @@ -783,7 +783,7 @@ mod tests {
let slot = slot.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(slot.len(), 1);
let value = slot.value(0);
assert!(5_f64 - value < f64::EPSILON);
assert_eq!(5_f64, value);
}
4 => {
let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
Expand Down Expand Up @@ -835,7 +835,7 @@ mod tests {
assert!(!union.is_null(i));
assert_eq!(slot.len(), 1);
let value = slot.value(0);
assert!(value - 3_f64 < f64::EPSILON);
assert_eq!(value, 3_f64);
}
3 => {
let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
Expand Down Expand Up @@ -872,7 +872,7 @@ mod tests {
assert!(!new_union.is_null(i));
assert_eq!(slot.len(), 1);
let value = slot.value(0);
assert!(value - 3_f64 < f64::EPSILON);
assert_eq!(value, 3_f64);
}
2 => assert!(new_union.is_null(i)),
3 => {
Expand Down
2 changes: 1 addition & 1 deletion arrow/src/compute/kernels/aggregate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ mod tests {
#[test]
fn test_primitive_array_float_sum() {
let a = Float64Array::from(vec![1.1, 2.2, 3.3, 4.4, 5.5]);
assert!(16.5 - sum(&a).unwrap() < f64::EPSILON);
assert_eq!(16.5, sum(&a).unwrap());
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions arrow/src/compute/kernels/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1020,9 +1020,9 @@ mod tests {
let a = Float64Array::from(vec![15.0, 15.0, 8.0]);
let b = Float64Array::from(vec![5.0, 6.0, 8.0]);
let c = divide(&a, &b).unwrap();
assert!(3.0 - c.value(0) < f64::EPSILON);
assert!(2.5 - c.value(1) < f64::EPSILON);
assert!(1.0 - c.value(2) < f64::EPSILON);
assert_eq!(3.0, c.value(0));
assert_eq!(2.5, c.value(1));
assert_eq!(1.0, c.value(2));
}

#[test]
Expand Down
20 changes: 10 additions & 10 deletions arrow/src/compute/kernels/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2357,11 +2357,11 @@ mod tests {
let array = Arc::new(a) as ArrayRef;
let b = cast(&array, &DataType::Float64).unwrap();
let c = b.as_any().downcast_ref::<Float64Array>().unwrap();
assert!(5.0 - c.value(0) < f64::EPSILON);
assert!(6.0 - c.value(1) < f64::EPSILON);
assert!(7.0 - c.value(2) < f64::EPSILON);
assert!(8.0 - c.value(3) < f64::EPSILON);
assert!(9.0 - c.value(4) < f64::EPSILON);
assert_eq!(5.0, c.value(0));
assert_eq!(6.0, c.value(1));
assert_eq!(7.0, c.value(2));
assert_eq!(8.0, c.value(3));
assert_eq!(9.0, c.value(4));
}

#[test]
Expand Down Expand Up @@ -2483,10 +2483,10 @@ mod tests {
let values = arr.values();
let c = values.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(1, c.null_count());
assert!(7.0 - c.value(0) < f64::EPSILON);
assert!(8.0 - c.value(1) < f64::EPSILON);
assert_eq!(7.0, c.value(0));
assert_eq!(8.0, c.value(1));
assert!(!c.is_valid(2));
assert!(10.0 - c.value(3) < f64::EPSILON);
assert_eq!(10.0, c.value(3));
}

#[test]
Expand Down Expand Up @@ -2535,8 +2535,8 @@ mod tests {
let array = Arc::new(a) as ArrayRef;
let b = cast(&array, &DataType::Float64).unwrap();
let c = b.as_any().downcast_ref::<Float64Array>().unwrap();
assert!(1.0 - c.value(0) < f64::EPSILON);
assert!(0.0 - c.value(1) < f64::EPSILON);
assert_eq!(1.0, c.value(0));
assert_eq!(0.0, c.value(1));
assert!(!c.is_valid(2));
}

Expand Down
6 changes: 3 additions & 3 deletions arrow/src/csv/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1269,7 +1269,7 @@ mod tests {
.as_any()
.downcast_ref::<Float64Array>()
.unwrap();
assert!(57.653484 - lat.value(0) < f64::EPSILON);
assert_eq!(57.653484, lat.value(0));

// access data from a string array (ListArray<u8>)
let city = batch
Expand Down Expand Up @@ -1400,7 +1400,7 @@ mod tests {
.as_any()
.downcast_ref::<Float64Array>()
.unwrap();
assert!(57.653484 - lat.value(0) < f64::EPSILON);
assert_eq!(57.653484, lat.value(0));

// access data from a string array (ListArray<u8>)
let city = batch
Expand Down Expand Up @@ -1438,7 +1438,7 @@ mod tests {
.as_any()
.downcast_ref::<Float64Array>()
.unwrap();
assert!(57.653484 - lat.value(0) < f64::EPSILON);
assert_eq!(57.653484, lat.value(0));

// access data from a string array (ListArray<u8>)
let city = batch
Expand Down
14 changes: 7 additions & 7 deletions arrow/src/json/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1750,8 +1750,8 @@ mod tests {
.as_any()
.downcast_ref::<Float64Array>()
.unwrap();
assert!(2.0 - bb.value(0) < f64::EPSILON);
assert!(-3.5 - bb.value(1) < f64::EPSILON);
assert_eq!(2.0, bb.value(0));
assert_eq!(-3.5, bb.value(1));
let cc = batch
.column(c.0)
.as_any()
Expand Down Expand Up @@ -1873,8 +1873,8 @@ mod tests {
.as_any()
.downcast_ref::<Float32Array>()
.unwrap();
assert!(2.0 - bb.value(0) < f32::EPSILON);
assert!(-3.5 - bb.value(1) < f32::EPSILON);
assert_eq!(2.0, bb.value(0));
assert_eq!(-3.5, bb.value(1));
}

#[test]
Expand Down Expand Up @@ -1962,8 +1962,8 @@ mod tests {
let bb = bb.values();
let bb = bb.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(9, bb.len());
assert!(2.0 - bb.value(0) < f64::EPSILON);
assert!(-6.1 - bb.value(5) < f64::EPSILON);
assert_eq!(2.0, bb.value(0));
assert_eq!(-6.1, bb.value(5));
assert!(!bb.is_valid(7));

let cc = batch
Expand Down Expand Up @@ -2094,7 +2094,7 @@ mod tests {
let bb = bb.values();
let bb = bb.as_any().downcast_ref::<Float64Array>().unwrap();
assert_eq!(10, bb.len());
assert!(4.0 - bb.value(9) < f64::EPSILON);
assert_eq!(4.0, bb.value(9));

let cc = batch
.column(c.0)
Expand Down
2 changes: 0 additions & 2 deletions arrow/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@
#![allow(non_camel_case_types)]
#![deny(clippy::redundant_clone)]
#![allow(
// introduced to ignore lint errors when upgrading from 2020-04-22 to 2020-11-14
clippy::float_equality_without_abs,
clippy::type_complexity,
// upper_case_acronyms lint was introduced in Rust 1.51.
// It is triggered in the ffi module, and ipc::gen, which we have no control over
Expand Down

0 comments on commit 41fedad

Please sign in to comment.