You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/02/14 11:44:50 UTC
[arrow-rs] branch master updated: Enable clippy::float_equality_without_abs lint (#1305)
This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new 41fedad Enable clippy::float_equality_without_abs lint (#1305)
41fedad is described below
commit 41fedad38e43dbc91eeab42d552573209e9a48b6
Author: Sergey Glushchenko <gs...@gmail.com>
AuthorDate: Mon Feb 14 12:44:46 2022 +0100
Enable clippy::float_equality_without_abs lint (#1305)
---
arrow/src/array/array_union.rs | 10 +++++-----
arrow/src/compute/kernels/aggregate.rs | 2 +-
arrow/src/compute/kernels/arithmetic.rs | 6 +++---
arrow/src/compute/kernels/cast.rs | 20 ++++++++++----------
arrow/src/csv/reader.rs | 6 +++---
arrow/src/json/reader.rs | 14 +++++++-------
arrow/src/lib.rs | 2 --
7 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/arrow/src/array/array_union.rs b/arrow/src/array/array_union.rs
index 0e1eb38..2a4a42d 100644
--- a/arrow/src/array/array_union.rs
+++ b/arrow/src/array/array_union.rs
@@ -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
@@ -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();
@@ -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();
@@ -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();
@@ -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 => {
diff --git a/arrow/src/compute/kernels/aggregate.rs b/arrow/src/compute/kernels/aggregate.rs
index a385c67..0750785 100644
--- a/arrow/src/compute/kernels/aggregate.rs
+++ b/arrow/src/compute/kernels/aggregate.rs
@@ -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]
diff --git a/arrow/src/compute/kernels/arithmetic.rs b/arrow/src/compute/kernels/arithmetic.rs
index dcdfa95..04a7e2f 100644
--- a/arrow/src/compute/kernels/arithmetic.rs
+++ b/arrow/src/compute/kernels/arithmetic.rs
@@ -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]
diff --git a/arrow/src/compute/kernels/cast.rs b/arrow/src/compute/kernels/cast.rs
index e3900aa..9089e78 100644
--- a/arrow/src/compute/kernels/cast.rs
+++ b/arrow/src/compute/kernels/cast.rs
@@ -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]
@@ -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]
@@ -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));
}
diff --git a/arrow/src/csv/reader.rs b/arrow/src/csv/reader.rs
index 03a45ab..65bff2a 100644
--- a/arrow/src/csv/reader.rs
+++ b/arrow/src/csv/reader.rs
@@ -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
@@ -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
@@ -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
diff --git a/arrow/src/json/reader.rs b/arrow/src/json/reader.rs
index eb78e0a..a8fe7a1 100644
--- a/arrow/src/json/reader.rs
+++ b/arrow/src/json/reader.rs
@@ -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()
@@ -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]
@@ -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
@@ -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)
diff --git a/arrow/src/lib.rs b/arrow/src/lib.rs
index 92afd02..68b98a6 100644
--- a/arrow/src/lib.rs
+++ b/arrow/src/lib.rs
@@ -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