Skip to content

Commit

Permalink
python polars: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Jan 2, 2022
1 parent bdf5176 commit ae69335
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 43 deletions.
2 changes: 1 addition & 1 deletion py-polars/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ impl PyDataFrame {
// call the lambda and get a python side DataFrame wrapper
let result_df_wrapper = match lambda.call1(py, (python_df_wrapper,)) {
Ok(pyobj) => pyobj,
Err(e) => panic!("UDF failed: {}", e.pvalue(py).to_string()),
Err(e) => panic!("UDF failed: {}", e.pvalue(py)),
};
// unpack the wrapper in a PyDataFrame
let py_pydf = result_df_wrapper.getattr(py, "_df").expect(
Expand Down
11 changes: 4 additions & 7 deletions py-polars/src/lazy/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub(crate) fn call_lambda_with_series(
// call the lambda and get a python side Series wrapper
match lambda.call1(py, (python_series_wrapper,)) {
Ok(pyobj) => pyobj,
Err(e) => panic!("python apply failed: {}", e.pvalue(py).to_string()),
Err(e) => panic!("python apply failed: {}", e.pvalue(py)),
}
}

Expand Down Expand Up @@ -86,12 +86,9 @@ pub(crate) fn binary_lambda(lambda: &PyObject, a: Series, b: Series) -> Result<S
let result_series_wrapper =
match lambda.call1(py, (python_series_wrapper_a, python_series_wrapper_b)) {
Ok(pyobj) => pyobj,
Err(e) => panic!(
"custom python function failed: {}",
e.pvalue(py).to_string()
),
Err(e) => panic!("custom python function failed: {}", e.pvalue(py)),
};
let pyseries = if let Some(expr) = result_series_wrapper.getattr(py, "_pyexpr").ok() {
let pyseries = if let Ok(expr) = result_series_wrapper.getattr(py, "_pyexpr") {
let pyexpr = expr.extract::<PyExpr>(py).unwrap();
let expr = pyexpr.inner;
let df = DataFrame::new_no_checks(vec![]);
Expand Down Expand Up @@ -191,7 +188,7 @@ pub(crate) fn call_lambda_with_series_slice(
// call the lambda and get a python side Series wrapper
match lambda.call1(py, (wrapped_s,)) {
Ok(pyobj) => pyobj,
Err(e) => panic!("python apply failed: {}", e.pvalue(py).to_string()),
Err(e) => panic!("python apply failed: {}", e.pvalue(py)),
}
}

Expand Down
38 changes: 4 additions & 34 deletions py-polars/src/lazy/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl PyLazyGroupBy {
// call the lambda and get a python side DataFrame wrapper
let result_df_wrapper = match lambda.call1(py, (python_df_wrapper,)) {
Ok(pyobj) => pyobj,
Err(e) => panic!("UDF failed: {}", e.pvalue(py).to_string()),
Err(e) => panic!("UDF failed: {}", e.pvalue(py)),
};
// unpack the wrapper in a PyDataFrame
let py_pydf = result_df_wrapper.getattr(py, "_df").expect(
Expand Down Expand Up @@ -84,38 +84,6 @@ impl From<LazyFrame> for PyLazyFrame {
}
}

// pub fn apply(&mut self, lambda: PyObject) -> PyLazyFrame {
// let lgb = self.lgb.take().unwrap();
//
// let function = move |df: DataFrame| {
// let gil = Python::acquire_gil();
// let py = gil.python();
// // get the pypolars module
// let pypolars = PyModule::import(py, "polars").unwrap();
//
// // create a PyDataFrame struct/object for Python
// let pydf = PyDataFrame::new(df);
//
// // Wrap this PySeries object in the python side DataFrame wrapper
// let python_df_wrapper = pypolars.getattr("wrap_df").unwrap().call1((pydf,)).unwrap();
//
// // call the lambda and get a python side DataFrame wrapper
// let result_df_wrapper = match lambda.call1(py, (python_df_wrapper,)) {
// Ok(pyobj) => pyobj,
// Err(e) => panic!("UDF failed: {}", e.pvalue(py).to_string()),
// };
// // unpack the wrapper in a PyDataFrame
// let py_pydf = result_df_wrapper.getattr(py, "_df").expect(
// "Could net get DataFrame attribute '_df'. Make sure that you return a DataFrame object.",
// );
// // Downcast to Rust
// let pydf = py_pydf.extract::<PyDataFrame>(py).unwrap();
// // Finally get the actual DataFrame
// Ok(pydf.df)
// };
// lgb.apply(function).into()
// }

#[pymethods]
#[allow(clippy::should_implement_trait)]
impl PyLazyFrame {
Expand Down Expand Up @@ -304,6 +272,7 @@ impl PyLazyFrame {
PyLazyGroupBy { lgb: Some(lazy_gb) }
}

#[allow(clippy::too_many_arguments)]
pub fn groupby_dynamic(
&mut self,
time_column: String,
Expand Down Expand Up @@ -337,6 +306,7 @@ impl PyLazyFrame {
PyLazyGroupBy { lgb: Some(lazy_gb) }
}

#[allow(clippy::too_many_arguments)]
pub fn join(
&mut self,
other: PyLazyFrame,
Expand Down Expand Up @@ -526,7 +496,7 @@ impl PyLazyFrame {
// call the lambda and get a python side Series wrapper
let result_df_wrapper = match lambda.call1(py, (python_df_wrapper,)) {
Ok(pyobj) => pyobj,
Err(e) => panic!("UDF failed: {}", e.pvalue(py).to_string()),
Err(e) => panic!("UDF failed: {}", e.pvalue(py)),
};
// unpack the wrapper in a PyDataFrame
let py_pydf = result_df_wrapper.getattr(py, "_df").expect(
Expand Down
2 changes: 1 addition & 1 deletion py-polars/src/series.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ impl PySeries {
v.append(python.None()).unwrap();
}
Some(s) => {
let pylst = primitive_to_list(&inner_dtype, s.as_ref());
let pylst = primitive_to_list(inner_dtype, s.as_ref());
v.append(pylst).unwrap();
}
}
Expand Down

0 comments on commit ae69335

Please sign in to comment.