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

build(python): Update pyo3 and numpy crates to version 0.23 #20111

Merged
merged 37 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f3af8c0
chore: update to pyo3 v0.23
bschoenmaeckers Dec 2, 2024
9bc2104
fix deprecation warnings in `polars-plan`
bschoenmaeckers Dec 2, 2024
dd96e31
fix deprecation warnings in `polars-utils`
bschoenmaeckers Dec 2, 2024
7843535
fix deprecation warnings in `py-polars`
bschoenmaeckers Dec 2, 2024
c4b62c3
Fix bunch of deprecation warnings
bschoenmaeckers Dec 2, 2024
c20728e
fix deadlock
bschoenmaeckers Dec 4, 2024
b42e04d
ignore windows debug symbols
bschoenmaeckers Dec 4, 2024
8aa59a8
Store static module imports in `GILOnceCell`
bschoenmaeckers Dec 4, 2024
1feac34
Merge branch 'main' into pyo3-0.23
bschoenmaeckers Dec 4, 2024
185a33b
impl `IntoPyObject` for `Wrap<Duration>`
bschoenmaeckers Dec 4, 2024
5023540
impl `IntoPyObject` for `Wrap<TimeUnit>`
bschoenmaeckers Dec 4, 2024
510e980
impl `IntoPyObject` for `Wrap<CategoricalOrdering>`
bschoenmaeckers Dec 4, 2024
1f56b73
impl `IntoPyObject` for `Wrap<&Schema>`
bschoenmaeckers Dec 4, 2024
a2a1464
impl `IntoPyObject` for `Wrap<InequalityOperator>`
bschoenmaeckers Dec 4, 2024
9e2224f
impl `IntoPyObject` for `Wrap<Operator>`
bschoenmaeckers Dec 4, 2024
6a3e06e
impl `IntoPyObject` for `Wrap<AnyValue>`
bschoenmaeckers Dec 4, 2024
6b9a8ff
return `PyResult` from `PuSeries::to_list`
bschoenmaeckers Dec 5, 2024
aedd938
impl `IntoPyObject` for `&Wrap<&DateChunked>`
bschoenmaeckers Dec 5, 2024
ae76721
impl `IntoPyObject` for `&Wrap<&BinaryChunked>`
bschoenmaeckers Dec 5, 2024
32a19b5
impl `IntoPyObject` for `&Wrap<&DatetimeChunked>`
bschoenmaeckers Dec 5, 2024
a66058d
impl `IntoPyObject` for `&Wrap<&DecimalChunked>`
bschoenmaeckers Dec 5, 2024
d42755b
impl `IntoPyObject` for `&Wrap<&StructChunked>`
bschoenmaeckers Dec 5, 2024
ca0a4f8
impl `IntoPyObject` for `&Wrap<&StringChunked>`
bschoenmaeckers Dec 5, 2024
c84d134
impl `IntoPyObject` for `&Wrap<&DurationChunked>`
bschoenmaeckers Dec 5, 2024
9db6be7
impl `IntoPyObject` for `&Wrap<&TimeChunked>`
bschoenmaeckers Dec 5, 2024
7b66aa1
impl `IntoPyObject` for `&Wrap<AnyValue<'_>>` and `&'a ObjectValue`
bschoenmaeckers Dec 6, 2024
0dfea4b
impl `IntoPyObject` for `BufferInfo`
bschoenmaeckers Dec 6, 2024
95eb735
impl `IntoPyObject` for `&Wrap<DataType>`
bschoenmaeckers Dec 6, 2024
8908700
Fix more deprecation warnings
bschoenmaeckers Dec 6, 2024
84f04d4
Update to pyo3 git master
bschoenmaeckers Dec 6, 2024
6790fa5
Merge remote-tracking branch 'origin/main' into pyo3-0.23
bschoenmaeckers Dec 9, 2024
c6e4a35
Fix deprecation warnings in `lazyframe/visitor/nodes.rs`
bschoenmaeckers Dec 9, 2024
7392d6f
Fix deprecation warnings in `lazyframe/visitor/expr_nodes.rs`
bschoenmaeckers Dec 9, 2024
1a86882
fix deprecation warnings in `polars-python.interop`
bschoenmaeckers Dec 9, 2024
a20feb9
Remove todo
bschoenmaeckers Dec 10, 2024
ef8568f
Merge remote-tracking branch 'origin/main' into pyo3-0.23
bschoenmaeckers Dec 10, 2024
73f3a90
Merge remote-tracking branch 'origin/main' into pyo3-0.23
bschoenmaeckers Dec 12, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.iml
*.so
*.pyd
*.pdb
*.ipynb
.ENV
.env
Expand Down
41 changes: 15 additions & 26 deletions Cargo.lock

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

6 changes: 4 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 = { git = "https://github.com/bschoenmaeckers/pyo3.git", branch = "release-0.23" }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add back the temporary fix for PyO3/pyo3#4764 until PyO3/pyo3#4766 is released. If that is desirable.

rand = "0.8"
rand_distr = "0.4"
raw-cpuid = "11"
Expand Down Expand Up @@ -136,6 +136,8 @@ features = [
[patch.crates-io]
# packed_simd_2 = { git = "https://github.com/rust-lang/packed_simd", rev = "e57c7ba11386147e6d2cbad7c88f376aab4bdc86" }
# simd-json = { git = "https://github.com/ritchie46/simd-json", branch = "alignment" }
pyo3 = { git = "https://github.com/bschoenmaeckers/pyo3.git", branch = "release-0.23" }
pyo3-ffi = { git = "https://github.com/bschoenmaeckers/pyo3.git", branch = "release-0.23" }

[profile.mindebug-dev]
inherits = "dev"
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
8 changes: 4 additions & 4 deletions crates/polars-plan/src/dsl/python_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ impl PythonUdfExpression {

// Load UDF
Python::with_gil(|py| {
let pickle = PyModule::import_bound(py, "pickle")
let pickle = PyModule::import(py, "pickle")
.expect("unable to import 'pickle'")
.getattr("loads")
.unwrap();
let arg = (PyBytes::new_bound(py, remainder),);
let arg = (PyBytes::new(py, remainder),);
let python_function = pickle.call1(arg).map_err(from_pyerr)?;
Ok(Arc::new(Self::new(
python_function.into(),
Expand Down Expand Up @@ -136,15 +136,15 @@ impl ColumnsUdf for PythonUdfExpression {

Python::with_gil(|py| {
// Try pickle to serialize the UDF, otherwise fall back to cloudpickle.
let pickle = PyModule::import_bound(py, "pickle")
let pickle = PyModule::import(py, "pickle")
.expect("unable to import 'pickle'")
.getattr("dumps")
.unwrap();
let pickle_result = pickle.call1((self.python_function.clone_ref(py),));
let (dumped, use_cloudpickle) = match pickle_result {
Ok(dumped) => (dumped, false),
Err(_) => {
let cloudpickle = PyModule::import_bound(py, "cloudpickle")
let cloudpickle = PyModule::import(py, "cloudpickle")
.map_err(from_pyerr)?
.getattr("dumps")
.unwrap();
Expand Down
12 changes: 6 additions & 6 deletions crates/polars-python/src/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use crate::lazyframe::visit::NodeTraverser;
use crate::{PyDataFrame, PyLazyFrame};

#[pyfunction]
pub fn prepare_cloud_plan(lf: PyLazyFrame, py: Python) -> PyResult<PyObject> {
pub fn prepare_cloud_plan(lf: PyLazyFrame, py: Python<'_>) -> PyResult<Bound<'_, PyBytes>> {
let plan = lf.ldf.logical_plan;
let bytes = polars::prelude::prepare_cloud_plan(plan).map_err(PyPolarsErr::from)?;

Ok(PyBytes::new_bound(py, &bytes).to_object(py))
Ok(PyBytes::new(py, &bytes))
}

/// Take a serialized `IRPlan` and execute it on the GPU engine.
Expand Down Expand Up @@ -62,13 +62,13 @@ fn gpu_post_opt(
expr_arena: &mut Arena<AExpr>,
) -> PolarsResult<()> {
// Get cuDF Python function.
let cudf = PyModule::import_bound(py, intern!(py, "cudf_polars")).unwrap();
let cudf = PyModule::import(py, intern!(py, "cudf_polars")).unwrap();
let lambda = cudf.getattr(intern!(py, "execute_with_cudf")).unwrap();

// Define cuDF config.
let polars = PyModule::import_bound(py, intern!(py, "polars")).unwrap();
let polars = PyModule::import(py, intern!(py, "polars")).unwrap();
let engine = polars.getattr(intern!(py, "GPUEngine")).unwrap();
let kwargs = [("raise_on_fail", true)].into_py_dict_bound(py);
let kwargs = [("raise_on_fail", true)].into_py_dict(py).unwrap();
let engine = engine.call((), Some(&kwargs)).unwrap();

// Define node traverser.
Expand All @@ -79,7 +79,7 @@ fn gpu_post_opt(

// Pass the node visitor which allows the Python callback to replace parts of the query plan.
// Remove "cuda" or specify better once we have multiple post-opt callbacks.
let kwargs = [("config", engine)].into_py_dict_bound(py);
let kwargs = [("config", engine)].into_py_dict(py).unwrap();
lambda
.call((nt,), Some(&kwargs))
.map_err(|e| polars_err!(ComputeError: "'cuda' conversion failed: {}", e))?;
Expand Down
Loading
Loading