Skip to content

Commit

Permalink
refactor: fix some lints in Rust code
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennebacher authored and eitsupi committed Feb 3, 2025
1 parent 68a724a commit 8107f76
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 79 deletions.
8 changes: 4 additions & 4 deletions src/rust/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,21 +625,21 @@ impl TryFrom<StringSexp> for Wrap<NullValues> {
let names = null_values.get_names().unwrap();
let res = names
.into_iter()
.zip(values.into_iter())
.zip(values)
.map(|(xi, yi)| (xi.into(), yi.into()))
.collect::<Vec<(PlSmallStr, PlSmallStr)>>();
return Ok(Wrap(NullValues::Named(res)));
Ok(Wrap(NullValues::Named(res)))
} else if null_values.len() == 1 {
let vals = null_values.to_vec();
let val = *(vals.get(0).unwrap());
let val = *(vals.first().unwrap());
return Ok(Wrap(NullValues::AllColumnsSingle(val.into())));
} else {
let vals = null_values
.to_vec()
.into_iter()
.map(|x| x.into())
.collect::<Vec<PlSmallStr>>();
return Ok(Wrap(NullValues::AllColumns(vals.into())));
return Ok(Wrap(NullValues::AllColumns(vals)));
}
}
}
Expand Down
21 changes: 6 additions & 15 deletions src/rust/src/expr/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,15 +767,15 @@ impl PlRExpr {

fn backward_fill(&self, limit: Option<NumericScalar>) -> Result<Self> {
let limit: FillNullLimit = match limit {
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0.into()),
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0),
None => None,
};
Ok(self.inner.clone().backward_fill(limit).into())
}

fn forward_fill(&self, limit: Option<NumericScalar>) -> Result<Self> {
let limit: FillNullLimit = match limit {
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0.into()),
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0),
None => None,
};
Ok(self.inner.clone().forward_fill(limit).into())
Expand All @@ -800,7 +800,7 @@ impl PlRExpr {
limit: Option<NumericScalar>,
) -> Result<Self> {
let limit: FillNullLimit = match limit {
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0.into()),
Some(x) => Some(<Wrap<u32>>::try_from(x)?.0),
None => None,
};
let strategy = parse_fill_null_strategy(strategy, limit)?;
Expand Down Expand Up @@ -870,10 +870,7 @@ impl PlRExpr {
labels: Option<StringSexp>,
) -> Result<Self> {
let breaks: Vec<f64> = breaks.as_slice_f64().into();
let labels = match labels {
Some(x) => Some(x.to_vec()),
None => None,
};
let labels = labels.map(|x| x.to_vec());
Ok(self
.inner
.clone()
Expand All @@ -890,10 +887,7 @@ impl PlRExpr {
labels: Option<StringSexp>,
) -> Result<Self> {
let probs: Vec<f64> = probs.as_slice_f64().into();
let labels = match labels {
Some(x) => Some(x.to_vec()),
None => None,
};
let labels = labels.map(|x| x.to_vec());
Ok(self
.inner
.clone()
Expand All @@ -910,10 +904,7 @@ impl PlRExpr {
labels: Option<StringSexp>,
) -> Result<Self> {
let n_bins = <Wrap<usize>>::try_from(n_bins)?.0;
let labels = match labels {
Some(x) => Some(x.to_vec()),
None => None,
};
let labels = labels.map(|x| x.to_vec());
Ok(self
.inner
.clone()
Expand Down
40 changes: 8 additions & 32 deletions src/rust/src/expr/rolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -60,10 +57,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -108,10 +102,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -156,10 +147,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -208,10 +196,7 @@ impl PlRExpr {
) -> Result<Self> {
let ddof = <Wrap<u8>>::try_from(ddof)?.0;
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -262,10 +247,7 @@ impl PlRExpr {
) -> Result<Self> {
let ddof = <Wrap<u8>>::try_from(ddof)?.0;
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -314,10 +296,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
None => window_size,
Expand Down Expand Up @@ -364,10 +343,7 @@ impl PlRExpr {
min_periods: Option<NumericScalar>,
) -> Result<Self> {
let window_size = <Wrap<usize>>::try_from(window_size)?.0;
let weights: Option<Vec<f64>> = match weights {
Some(x) => Some(x.as_slice_f64().into()),
None => None,
};
let weights: Option<Vec<f64>> = weights.map(|x| x.as_slice_f64().into());
let interpolation = <Wrap<QuantileMethod>>::try_from(interpolation)?.0;
let min_periods: usize = match min_periods {
Some(x) => <Wrap<usize>>::try_from(x)?.0,
Expand Down
39 changes: 12 additions & 27 deletions src/rust/src/lazyframe/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,10 @@ impl PlRLazyFrame {
.copied()
.map_err(RPolarsErr::from)?;

let row_index = match row_index_name {
Some(x) => Some(RowIndex {
let row_index = row_index_name.map(|x| RowIndex {
name: x.into(),
offset: row_index_offset,
}),
None => None,
};
});

let overwrite_dtype = match overwrite_dtype {
Some(x) => Some(<Wrap<Schema>>::try_from(x)?.0),
Expand All @@ -406,9 +403,7 @@ impl PlRLazyFrame {
let cloud_options = match storage_options {
Some(x) => {
let out = <Wrap<Vec<(String, String)>>>::try_from(x).map_err(|_| {
RPolarsErr::Other(format!(
"`storage_options` must be a named character vector"
))
RPolarsErr::Other("`storage_options` must be a named character vector".to_string())
})?;
Some(out.0)
}
Expand Down Expand Up @@ -509,13 +504,10 @@ impl PlRLazyFrame {
None => None,
};

let row_index = match row_index_name {
Some(x) => Some(RowIndex {
let row_index = row_index_name.map(|x| RowIndex {
name: x.into(),
offset: row_index_offset,
}),
None => None,
};
});

let hive_options = HiveOptions {
enabled: hive_partitioning,
Expand All @@ -533,7 +525,7 @@ impl PlRLazyFrame {
low_memory,
cloud_options: None,
use_statistics,
schema: schema.map(|x| Arc::new(x)),
schema: schema.map(Arc::new),
hive_options,
glob,
include_file_paths: include_file_paths.map(|x| x.into()),
Expand All @@ -547,9 +539,7 @@ impl PlRLazyFrame {
let cloud_options = match storage_options {
Some(x) => {
let out = <Wrap<Vec<(String, String)>>>::try_from(x).map_err(|_| {
RPolarsErr::Other(format!(
"`storage_options` must be a named character vector"
))
RPolarsErr::Other("`storage_options` must be a named character vector".to_string())
})?;
Some(out.0)
}
Expand Down Expand Up @@ -631,13 +621,10 @@ impl PlRLazyFrame {
None => None,
};

let row_index = match row_index_name {
Some(x) => Some(RowIndex {
let row_index = row_index_name.map(|x| RowIndex {
name: x.into(),
offset: row_index_offset,
}),
None => None,
};
});

let first_path = source.first().unwrap().clone().into();

Expand All @@ -648,9 +635,7 @@ impl PlRLazyFrame {
let cloud_options = match storage_options {
Some(x) => {
let out = <Wrap<Vec<(String, String)>>>::try_from(x).map_err(|_| {
RPolarsErr::Other(format!(
"`storage_options` must be a named character vector"
))
RPolarsErr::Other("`storage_options` must be a named character vector".to_string())
})?;
Some(out.0)
}
Expand Down Expand Up @@ -682,8 +667,8 @@ impl PlRLazyFrame {
.with_n_rows(n_rows)
.low_memory(low_memory)
.with_rechunk(rechunk)
.with_schema(schema.map(|schema| Arc::new(schema)))
.with_schema_overwrite(schema_overrides.map(|x| Arc::new(x)))
.with_schema(schema.map(Arc::new))
.with_schema_overwrite(schema_overrides.map(Arc::new))
.with_row_index(row_index)
.with_ignore_errors(ignore_errors)
.with_include_file_paths(include_file_paths.map(|x| x.into()))
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/series/construction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl PlRSeries {
} else {
let left_u32 = *l as u32;
let right_u32 = *r as u32;
let out_u64 = (left_u32 as u64) << 32 | right_u32 as u64;
let out_u64 = ((left_u32 as u64) << 32) | right_u32 as u64;
Some(
i64::from_ne_bytes(
(out_u64.wrapping_sub(9_223_372_036_854_775_808u64)).to_ne_bytes(),
Expand Down

0 comments on commit 8107f76

Please sign in to comment.