Skip to content

Commit

Permalink
chore: update to pyo3 v0.23
Browse files Browse the repository at this point in the history
  • Loading branch information
bschoenmaeckers committed Dec 2, 2024
1 parent 31b7bb9 commit 97f1ea3
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 59 deletions.
36 changes: 15 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ memmap = { package = "memmap2", version = "0.9" }
multiversion = "0.7"
ndarray = { version = "0.16", default-features = false }
num-traits = "0.2"
numpy = "0.22"
numpy = "0.23"
object_store = { version = "0.11", default-features = false }
once_cell = "1"
parking_lot = "0.12"
percent-encoding = "2.3"
pin-project-lite = "0.2"
pyo3 = "0.22"
pyo3 = "0.23"
rand = "0.8"
rand_distr = "0.4"
raw-cpuid = "11"
Expand Down
7 changes: 7 additions & 0 deletions crates/polars-error/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod warning;

use std::borrow::Cow;
use std::collections::TryReserveError;
use std::convert::Infallible;
use std::error::Error;
use std::fmt::{self, Display, Formatter, Write};
use std::ops::Deref;
Expand Down Expand Up @@ -168,6 +169,12 @@ impl From<TryReserveError> for PolarsError {
}
}

impl From<Infallible> for PolarsError {
fn from(_: Infallible) -> Self {
unreachable!()
}
}

pub type PolarsResult<T> = Result<T, PolarsError>;

impl PolarsError {
Expand Down
16 changes: 8 additions & 8 deletions crates/polars-mem-engine/src/executors/scan/python_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use polars_core::error::to_compute_err;
use polars_core::utils::accumulate_dataframes_vertical;
use pyo3::exceptions::PyStopIteration;
use pyo3::prelude::*;
use pyo3::types::PyBytes;
use pyo3::{intern, PyTypeInfo};
use pyo3::types::{PyBytes, PyNone};
use pyo3::{intern, IntoPyObjectExt, PyTypeInfo};

use super::*;

Expand Down Expand Up @@ -41,7 +41,7 @@ impl Executor for PythonScanExec {
let with_columns = self.options.with_columns.take();
let n_rows = self.options.n_rows.take();
Python::with_gil(|py| {
let pl = PyModule::import_bound(py, intern!(py, "polars")).unwrap();
let pl = PyModule::import(py, intern!(py, "polars")).unwrap();
let utils = pl.getattr(intern!(py, "_utils")).unwrap();
let callable = utils.getattr(intern!(py, "_execute_from_rust")).unwrap();

Expand All @@ -50,14 +50,14 @@ impl Executor for PythonScanExec {
let with_columns = with_columns.map(|cols| cols.iter().cloned().collect::<Vec<_>>());

let predicate = match &self.options.predicate {
PythonPredicate::PyArrow(s) => s.into_py(py),
PythonPredicate::None => None::<()>.into_py(py),
PythonPredicate::PyArrow(s) => s.into_bound_py_any(py).unwrap(),
PythonPredicate::None => None::<()>.into_bound_py_any(py).unwrap(),
PythonPredicate::Polars(_) => {
assert!(self.predicate.is_some(), "should be set");

match &self.predicate_serialized {
None => None::<()>.into_py(py),
Some(buf) => PyBytes::new_bound(py, buf).to_object(py),
None => PyNone::get(py).to_owned().into_any(),
Some(buf) => PyBytes::new(py, buf).into_any(),
}
},
};
Expand Down Expand Up @@ -125,7 +125,7 @@ impl Executor for PythonScanExec {
}
chunks.push(df)
},
Err(err) if err.matches(py, PyStopIteration::type_object_bound(py)) => break,
Err(err) if err.matches(py, PyStopIteration::type_object(py))? => break,
Err(err) => {
polars_bail!(ComputeError: "caught exception during execution of a Python source, exception: {}", err)
},
Expand Down
6 changes: 4 additions & 2 deletions crates/polars-python/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ fn struct_dict<'a>(
) -> PyObject {
let dict = PyDict::new_bound(py);
for (fld, val) in flds.iter().zip(vals) {
dict.set_item(fld.name().as_str(), Wrap(val)).unwrap()
dict.set_item(fld.name().as_str(), Wrap(val).into_py(py))
.unwrap()
}
dict.into_py(py)
}
Expand Down Expand Up @@ -598,7 +599,8 @@ impl IntoPy<PyObject> for Wrap<&Schema> {
fn into_py(self, py: Python<'_>) -> PyObject {
let dict = PyDict::new_bound(py);
for (k, v) in self.0.iter() {
dict.set_item(k.as_str(), Wrap(v.clone())).unwrap();
dict.set_item(k.as_str(), Wrap(v.clone()).to_object(py))
.unwrap();
}
dict.into_py(py)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-python/src/lazyframe/general.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1226,7 +1226,7 @@ impl PyLazyFrame {
let schema_dict = PyDict::new_bound(py);
schema.iter_fields().for_each(|fld| {
schema_dict
.set_item(fld.name().as_str(), Wrap(fld.dtype().clone()))
.set_item(fld.name().as_str(), Wrap(fld.dtype().clone()).to_object(py))
.unwrap()
});
Ok(schema_dict.to_object(py))
Expand Down
1 change: 1 addition & 0 deletions crates/polars-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![allow(non_local_definitions)]
#![allow(clippy::too_many_arguments)] // Python functions can have many arguments due to default arguments
#![allow(clippy::disallowed_types)]
#![allow(warnings)]

#[cfg(feature = "csv")]
pub mod batched_csv;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-python/src/map/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn get_iters_skip(df: &DataFrame, n: usize) -> Vec<std::iter::Skip<SeriesIter>>
// the return type is Union[PySeries, PyDataFrame] and a boolean indicating if it is a dataframe or not
pub fn apply_lambda_unknown<'a>(
df: &'a DataFrame,
py: Python,
py: Python<'a>,
lambda: Bound<'a, PyAny>,
inference_size: usize,
) -> PyResult<(PyObject, bool)> {
Expand Down
Loading

0 comments on commit 97f1ea3

Please sign in to comment.