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 lints #625

Merged
merged 6 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/extendr-wrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ RPolarsRField$set_datatype_mut <- function(datatype) invisible(.Call(wrap__RPola

RPolarsErr <- new.env(parent = emptyenv())

RPolarsErr$default <- function() .Call(wrap__RPolarsErr__default)

RPolarsErr$new <- function() .Call(wrap__RPolarsErr__new)

RPolarsErr$contexts <- function() .Call(wrap__RPolarsErr__contexts, self)
Expand Down Expand Up @@ -1271,7 +1273,7 @@ RPolarsStringCacheHolder <- new.env(parent = emptyenv())

RPolarsStringCacheHolder$hold <- function() .Call(wrap__RPolarsStringCacheHolder__hold)

RPolarsStringCacheHolder$release <- function() .Call(wrap__RPolarsStringCacheHolder__release, self)
RPolarsStringCacheHolder$release <- function() invisible(.Call(wrap__RPolarsStringCacheHolder__release, self))

#' @export
`$.RPolarsStringCacheHolder` <- function (self, name) { func <- RPolarsStringCacheHolder[[name]]; environment(func) <- environment(); func }
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/arrow_interop/to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ fn consume_arrow_stream_to_series(boxed_stream: Box<ffi::ArrowArrayStream>) -> R
let array = array_res?;
let series_res: pl::PolarsResult<pl::Series> =
std::convert::TryFrom::try_from(("df", array));
let series = series_res.map_err(polars_to_rpolars_err)?;
series

series_res.map_err(polars_to_rpolars_err)?
} else {
rerr()
.plain("Arrow array stream was empty")
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn concat_series(l: Robj, rechunk: Robj, to_supertypes: Robj) -> RResult<RPo
Ok(None) => Ok(Some(x)), // first fold, acc is None, just us x,
Ok(Some(acc)) => polars_core::utils::get_supertype(&acc, &x)
.ok_or(RPolarsErr::new().plain("Series' have no common supertype".to_string()))
.map(|dt| Some(dt)),
.map(Some),
});
let shared_supertype = shared_supertype?.expect("cannot be None, unless empty s_vec");

Expand Down
10 changes: 5 additions & 5 deletions src/rust/src/concurrent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ pub fn collect_with_r_func_support(lazy_df: pl::LazyFrame) -> RResult<RPolarsDat
} else {
#[cfg(feature = "rpolars_debug_print")]
println!("in collect: starting a concurrent handler");
let new_df = concurrent_handler(

#[cfg(feature = "rpolars_debug_print")]
println!("in collect: concurrent handler done");
concurrent_handler(
// closure 1: spawned by main thread
// tc is a ThreadCom which any child thread can use to submit R jobs to main thread
move |tc| {
Expand All @@ -116,10 +119,7 @@ pub fn collect_with_r_func_support(lazy_df: pl::LazyFrame) -> RResult<RPolarsDat
&CONFIG,
)
.map_err(|err| RPolarsErr::new().plain(err.to_string()))?
.map_err(polars_to_rpolars_err);
#[cfg(feature = "rpolars_debug_print")]
println!("in collect: concurrent handler done");
new_df
.map_err(polars_to_rpolars_err)
};

//wrap ok
Expand Down
1 change: 0 additions & 1 deletion src/rust/src/conversion_s_to_r.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ pub fn pl_series_to_list(
//TODO contribute extendr_api set_attrib mutates &self, change signature to surprise anyone
if tag_structs {
l.set_attrib("is_struct", true).unwrap();
} else {
};

Ok(l.into_robj())
Expand Down
3 changes: 1 addition & 2 deletions src/rust/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,7 @@ impl RPolarsLazyGroupBy {

fn ungroup(&self) -> RPolarsLazyFrame {
RPolarsLazyFrame(
pl::LazyFrame::from(self.lgb.logical_plan.clone())
.with_optimizations(self.opt_state.clone()),
pl::LazyFrame::from(self.lgb.logical_plan.clone()).with_optimizations(self.opt_state),
)
}

Expand Down
23 changes: 10 additions & 13 deletions src/rust/src/lazy/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ impl RPolarsExpr {
.map(|rank_method| {
let options = pl::RankOptions {
method: rank_method,
descending: descending,
descending,
};
RPolarsExpr(self.0.clone().rank(options, Some(0u64)))
})
Expand Down Expand Up @@ -1007,8 +1007,8 @@ impl RPolarsExpr {
.replace(
robj_to!(PLExpr, old)?,
robj_to!(PLExpr, new)?,
robj_to!(Option, PLExpr, default)?.map(|e| e),
robj_to!(Option, PLPolarsDataType, return_dtype)?.map(|dt| dt),
robj_to!(Option, PLExpr, default)?,
robj_to!(Option, PLPolarsDataType, return_dtype)?,
)
.into())
}
Expand Down Expand Up @@ -1052,7 +1052,7 @@ impl RPolarsExpr {
.clone()
.list()
.sort(SortOptions {
descending: descending,
descending,
..Default::default()
})
.with_fmt("list.sort")
Expand Down Expand Up @@ -1349,13 +1349,10 @@ impl RPolarsExpr {
}

pub fn dt_replace_time_zone(&self, tz: Nullable<String>, ambiguous: Robj) -> RResult<Self> {
Ok(RPolarsExpr(
self.0
.clone()
.dt()
.replace_time_zone(tz.into_option(), robj_to!(PLExpr, ambiguous)?)
.into(),
))
Ok(RPolarsExpr(self.0.clone().dt().replace_time_zone(
tz.into_option(),
robj_to!(PLExpr, ambiguous)?,
)))
}

pub fn dt_total_days(&self) -> RResult<Self> {
Expand Down Expand Up @@ -1877,7 +1874,7 @@ impl RPolarsExpr {
}

pub fn str_to_titlecase(&self) -> RResult<Self> {
f_str_to_titlecase(&self)
f_str_to_titlecase(self)
}

pub fn str_strip_chars(&self, matches: Robj) -> RResult<Self> {
Expand Down Expand Up @@ -2633,7 +2630,7 @@ pub fn robj_to_col(name: Robj, dotdotdot: Robj) -> RResult<RPolarsExpr> {

match () {
_ if name.is_string() && name.len() == 1 && dotdotdot.len() == 0 => {
Ok(RPolarsExpr::col(name.as_str().unwrap_or(&"")))
Ok(RPolarsExpr::col(name.as_str().unwrap_or("")))
}
_ if name.inherits("RPolarsDataType")
//or if name is a list and first element is RPolarsDataType
Expand Down
20 changes: 10 additions & 10 deletions src/rust/src/rbackground.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ pub fn deserialize_dataframe(bits: &[u8]) -> RResult<polars::prelude::DataFrame>
}

pub fn serialize_series(series: PSeries) -> RResult<Vec<u8>> {
serialize_dataframe(&mut std::iter::once(series).into_iter().collect())
serialize_dataframe(&mut std::iter::once(series).collect())
}

pub fn deserialize_series(bits: &[u8]) -> RResult<PSeries> {
Expand Down Expand Up @@ -371,7 +371,7 @@ impl InnerRBackgroundPool {

pub fn resize(&mut self, new_cap: usize) {
self.cap = new_cap;
while (self.active > self.cap) & (self.pool.len() > 0) {
while (self.active > self.cap) & (!self.pool.is_empty()) {
let handle = self
.pool
.pop_front()
Expand Down Expand Up @@ -426,10 +426,10 @@ impl RBackgroundPool {
drop(pool_guard); // avoid deadlock
#[cfg(feature = "rpolars_debug_print")]
println!("wait for freed handler");
let ok = Ok(rx.recv()?);

#[cfg(feature = "rpolars_debug_print")]
println!("thread was awoken queue and passed a handler");
ok
Ok(rx.recv()?)
}
}
.when("trying to rent a R process from the global R process pool")
Expand All @@ -454,11 +454,11 @@ impl RBackgroundPool {
Ok(())
}

pub fn reval<'t>(
&'t self,
pub fn reval(
&self,
raw_func: Vec<u8>,
raw_arg: Vec<u8>,
) -> RResult<impl FnOnce() -> RResult<Vec<u8>> + 't> {
) -> RResult<impl FnOnce() -> RResult<Vec<u8>> + '_> {
#[cfg(feature = "rpolars_debug_print")]
dbg!("reval");
let handler = self.lease()?;
Expand All @@ -477,11 +477,11 @@ impl RBackgroundPool {
})
}

pub fn rmap_series<'t>(
&'t self,
pub fn rmap_series(
&self,
raw_func: Vec<u8>,
series: PSeries,
) -> RResult<impl FnOnce() -> RResult<PSeries> + 't> {
) -> RResult<impl FnOnce() -> RResult<PSeries> + '_> {
#[cfg(feature = "rpolars_debug_print")]
dbg!("rmap_series");
let handler = self.lease()?;
Expand Down
6 changes: 3 additions & 3 deletions src/rust/src/rdataframe/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ impl RPolarsDataFrame {
}

pub fn select_at_idx(&self, idx: i32) -> List {
let expr_result = || -> Result<RPolarsSeries, String> {
let expr_result = {
self.0
.select_at_idx(idx as usize)
.map(|s| RPolarsSeries(s.clone()))
.ok_or_else(|| format!("select_at_idx: no series found at idx {:?}", idx))
}();
};
r_result_list(expr_result)
}

Expand Down Expand Up @@ -441,7 +441,7 @@ impl RPolarsDataFrame {
pub fn transpose(&self, keep_names_as: Robj, new_col_names: Robj) -> RResult<Self> {
let opt_s = robj_to!(Option, str, keep_names_as)?;
let opt_vec_s = robj_to!(Option, Vec, String, new_col_names)?;
let opt_either_vec_s = opt_vec_s.map(|vec_s| Either::Right(vec_s));
let opt_either_vec_s = opt_vec_s.map(Either::Right);
self.0
.transpose(opt_s, opt_either_vec_s)
.map_err(polars_to_rpolars_err)
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/rdatatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl RPolarsDataType {
}

pub fn new_struct(l: Robj) -> List {
let res = || -> std::result::Result<RPolarsDataType, String> {
let res = {
let len = l.len();

//iterate over R list and collect Fields and place in a Struct-datatype
Expand All @@ -127,7 +127,7 @@ impl RPolarsDataType {
.and_then(|iter| collect_hinted_result(len, iter))
.map_err(|err| format!("in pl$Struct: {}", err))
.map(|v_field| RPolarsDataType(pl::DataType::Struct(v_field)))
}();
};

r_result_list(res)
}
Expand Down
9 changes: 6 additions & 3 deletions src/rust/src/rpolarserr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ impl<T, E: Into<RPolarsErr>> WithRctx<T> for core::result::Result<T, E> {

#[extendr]
impl RPolarsErr {
fn default() -> Self {
Self::new()
}

pub fn new() -> Self {
RPolarsErr::new_from_ctxs(VecDeque::new())
}
Expand Down Expand Up @@ -238,12 +242,11 @@ impl std::fmt::Display for RPolarsErr {
if let Some(c) = &self.rcall {
writeln!(indented(f).ind(0), "During function call [{}]", c)?
}
Ok(self
.contexts
self.contexts
.iter()
.rev()
.enumerate()
.try_for_each(|(idx, ctx)| writeln!(indented(f).ind(idx + 1), "{}", ctx))?)
.try_for_each(|(idx, ctx)| writeln!(indented(f).ind(idx + 1), "{}", ctx))
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/rstringcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl RPolarsStringCacheHolder {

// R Garbage collection is not deterministic. Deleting all references to RPolarsStringCacheHolder
// will cause it to be dropped eventually. Calling release ensures immediate drop, leave back a None.
fn release(&mut self) -> () {
fn release(&mut self) {
let _opt_sch = self.0.take();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rust/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ impl RPolarsSeries {
};

//handle any return type from R and collect into Series
let s: extendr_api::Result<RPolarsSeries> = || -> extendr_api::Result<RPolarsSeries> {
let s: extendr_api::Result<RPolarsSeries> = {
match out_type {
Float64 => apply_output!(r_iter, strict, allow_fail_eval, Doubles, Float64Chunked),
Int32 => apply_output!(r_iter, strict, allow_fail_eval, Integers, Int32Chunked),
Expand Down Expand Up @@ -425,7 +425,7 @@ impl RPolarsSeries {

_ => todo!("this output type is not implemented"),
}
}();
};

let s = s.map(move |mut x| {
x.rename_mut(&format!("{}_apply", &self.name()));
Expand Down
Loading
Loading