-
Notifications
You must be signed in to change notification settings - Fork 333
cleanup clippy lints #316
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
cleanup clippy lints #316
Conversation
} | ||
match strategy { | ||
Strategy::best_score => match task { | ||
Task::regression => { | ||
sql += &format!("{predicate}\nORDER BY models.metrics->>'r2' DESC NULLS LAST"); | ||
let _ = write!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What come on clippy, this seems totally fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
format! does an extra allocation compared to write... 🤷♂️
Some(limit) => Some(limit.try_into().unwrap()), | ||
None => None, | ||
}; | ||
let limit: Option<usize> = limit.map(|limit| limit.try_into().unwrap()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, turns out you can map things like this...
@@ -66,7 +66,7 @@ fn model_predict_batch(model_id: i64, features: Vec<f32>, num_rows: i32) -> Vec< | |||
|
|||
match guard.get(&model_id) { | |||
Some(data) => { | |||
let bst = Booster::load_buffer(&data).unwrap(); | |||
let bst = Booster::load_buffer(data).unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a clippy warning? Should of been a compilation error...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler handles the extra dereference for you.
@@ -86,7 +90,7 @@ pub fn load_diabetes(limit: Option<usize>) -> (String, i64) { | |||
None => diabetes.num_samples, | |||
}; | |||
for i in 0..limit { | |||
let age = diabetes.data[(i * diabetes.num_features) + 0]; | |||
let age = diabetes.data[(i * diabetes.num_features)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hah!
@@ -153,6 +157,7 @@ pub fn load_digits(limit: Option<usize>) -> (String, i64) { | |||
let target = digits.target[i]; | |||
// shape the image in a 2d array | |||
let mut image = vec![vec![0.; 8]; 8]; | |||
#[allow(clippy::needless_range_loop)] // x & y are in fact used |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh no, don't get me started with these haha! Rubocop was plenty, thank you
@@ -13,15 +13,16 @@ use crate::orm::Algorithm; | |||
use crate::orm::Dataset; | |||
use crate::orm::Task; | |||
|
|||
#[allow(clippy::type_complexity)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy needs to get it together.
.as_str(), | ||
), | ||
) | ||
let task = Task::from_str(&task.unwrap_or_else(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok what's up with these. Why does not like expect
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect input is always executed which may have side effects or allocations. or_else is only executed if needed.
@@ -60,7 +60,7 @@ impl Model { | |||
(PgBuiltInOids::JSONBOID.oid(), search_args.into_datum()), | |||
]) | |||
).first(); | |||
if result.len() > 0 { | |||
if !result.is_empty() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
He got you there.
@@ -113,7 +113,7 @@ impl Snapshot { | |||
Spi::connect(|client| { | |||
let parts = self | |||
.relation_name | |||
.split(".") | |||
.split('.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ummm. Those are completely different data types if you ask me. Although we may have just removed a heap allocation so that's cool.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, so why allocate the string if you can just use a char instead...
@@ -279,7 +279,7 @@ impl Snapshot { | |||
(num_rows as f32 * self.test_size).round() as usize | |||
}; | |||
let num_train_rows = num_rows - num_test_rows; | |||
if num_train_rows <= 0 { | |||
if num_train_rows == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy never heard of off-by-one errors? == 0 always made me paranoid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's unsigned. Can't be < 0.
No description provided.