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

Fix clippy lint clippy::float_equality_without_abs #1305

Merged
merged 1 commit into from
Feb 14, 2022
Merged

Fix clippy lint clippy::float_equality_without_abs #1305

merged 1 commit into from
Feb 14, 2022

Conversation

gsserge
Copy link
Contributor

@gsserge gsserge commented Feb 12, 2022

Which issue does this PR close?

This is part of #1255

Rationale for this change

It's beneficial to run clippy as strict as possible.

What changes are included in this PR?

This PR enables clippy::float_equality_without_abs lint in the arrow crate and fixes all the relates testing code for this check to pass.

Are there any user-facing changes?

No.

@github-actions github-actions bot added the arrow Changes to the arrow crate label Feb 12, 2022
@jhorstmann
Copy link
Contributor

This float comparison with epsilon hint is a pet peeve of mine. The epsilon should not be needed if we expect a result that can be exactly represented in a float. I think the corresponding float_cmp lint was actually downgraded from "correctness" to "pedantic" recently, so I would prefer to rewrite those asserts without epsilon.

@codecov-commenter
Copy link

codecov-commenter commented Feb 13, 2022

Codecov Report

Merging #1305 (4673194) into master (8f7c56e) will increase coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1305      +/-   ##
==========================================
+ Coverage   83.01%   83.05%   +0.03%     
==========================================
  Files         180      180              
  Lines       52731    52824      +93     
==========================================
+ Hits        43775    43873      +98     
+ Misses       8956     8951       -5     
Impacted Files Coverage Δ
arrow/src/array/array_union.rs 90.71% <100.00%> (-0.05%) ⬇️
arrow/src/compute/kernels/aggregate.rs 73.33% <100.00%> (ø)
arrow/src/compute/kernels/arithmetic.rs 90.86% <100.00%> (ø)
arrow/src/compute/kernels/cast.rs 95.21% <100.00%> (ø)
arrow/src/csv/reader.rs 88.12% <100.00%> (ø)
arrow/src/json/reader.rs 83.39% <100.00%> (ø)
arrow/src/datatypes/datatype.rs 66.40% <0.00%> (-0.40%) ⬇️
parquet/src/arrow/converter.rs 63.96% <0.00%> (-0.39%) ⬇️
arrow/src/array/transform/mod.rs 84.51% <0.00%> (-0.13%) ⬇️
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f7c56e...4673194. Read the comment docs.

@alamb
Copy link
Contributor

alamb commented Feb 13, 2022

@jhorstmann to be clear, would you prefer that we keep the module level #![allow(clippy::float_equality_without_abs))]?

Or perhaps annotate the individual tests with

#![allow(clippy::float_equality_without_abs))]

Or something else?

@gsserge
Copy link
Contributor Author

gsserge commented Feb 13, 2022

It's also possible to allow only in the tests

#![cfg_attr(test, allow(clippy::float_equality_without_abs))]

but I'm actually curious how would you do the check without epsilon.

@jhorstmann
Copy link
Contributor

My suggestion was to remove the #![allow(clippy::float_equality_without_abs))], but also replace assertions like

assert!(5.0 - c.value(0) < f64::EPSILON);

with

assert_eq!(5.0, c.value(0));

where the asserted number can be exactly represented in floating point and where the operation does not involve any rounding. In some earlier rust version the latter assertion would have triggered the float_cmp lint, but I don't think it does that anymore for exact numbers.

@gsserge
Copy link
Contributor Author

gsserge commented Feb 13, 2022

@jhorstmann thanks for the explanation, I'm going to update the PR

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thank you @gsserge and @jhorstmann

@alamb alamb merged commit 41fedad into apache:master Feb 14, 2022
@gsserge gsserge deleted the clippy_float_equality_without_abs branch February 14, 2022 12:04
@alamb alamb changed the title Enable clippy::float_equality_without_abs lint Fix clippy lint clippy::float_equality_without_abs Feb 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants