Skip to content

Commit

Permalink
chore(python): More PyO3 0.21 Bound<> APIs, and finally disable gil-r…
Browse files Browse the repository at this point in the history
…efs backwards compat feature on pyo3 crate (#16143)

Co-authored-by: Itamar Turner-Trauring <itamar@pythonspeed.com>
  • Loading branch information
itamarst and pythonspeed committed May 14, 2024
1 parent 81cc802 commit 5b77f01
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 124 deletions.
9 changes: 5 additions & 4 deletions crates/polars-plan/src/dsl/python_udf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use polars_core::error::*;
use polars_core::frame::DataFrame;
use polars_core::prelude::Series;
use pyo3::prelude::*;
use pyo3::pybacked::PyBackedBytes;
use pyo3::types::PyBytes;
#[cfg(feature = "serde")]
use serde::ser::Error;
Expand Down Expand Up @@ -67,9 +68,9 @@ impl Serialize for PythonFunction {
let dumped = pickle
.call1((python_function,))
.map_err(|s| S::Error::custom(format!("cannot pickle {s}")))?;
let dumped = dumped.extract::<&PyBytes>().unwrap();
let dumped = dumped.extract::<PyBackedBytes>().unwrap();

serializer.serialize_bytes(dumped.as_bytes())
serializer.serialize_bytes(&dumped)
})
}
}
Expand Down Expand Up @@ -192,8 +193,8 @@ impl SeriesUdf for PythonUdfExpression {
let dumped = pickle
.call1((self.python_function.clone(),))
.map_err(from_pyerr)?;
let dumped = dumped.extract::<&PyBytes>().unwrap();
buf.extend_from_slice(dumped.as_bytes());
let dumped = dumped.extract::<PyBackedBytes>().unwrap();
buf.extend_from_slice(&dumped);
Ok(())
})
}
Expand Down
2 changes: 1 addition & 1 deletion py-polars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ ndarray = { workspace = true }
num-traits = { workspace = true }
numpy = { version = "0.21", default-features = false }
once_cell = { workspace = true }
pyo3 = { workspace = true, features = ["abi3-py38", "extension-module", "multiple-pymethods", "gil-refs"] }
pyo3 = { workspace = true, features = ["abi3-py38", "extension-module", "multiple-pymethods"] }
pyo3-built = { version = "0.5", optional = true }
recursive = { workspace = true }
serde_json = { workspace = true, optional = true }
Expand Down
4 changes: 2 additions & 2 deletions py-polars/src/conversion/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ pub(crate) fn py_object_to_any_value<'py>(
}

fn get_bytes<'py>(ob: &Bound<'py, PyAny>, _strict: bool) -> PyResult<AnyValue<'py>> {
let value = ob.extract::<&'py [u8]>().unwrap();
Ok(AnyValue::Binary(value))
let value = ob.extract::<Vec<u8>>().unwrap();
Ok(AnyValue::BinaryOwned(value))
}

fn get_date(ob: &Bound<'_, PyAny>, _strict: bool) -> PyResult<AnyValue<'static>> {
Expand Down
Loading

0 comments on commit 5b77f01

Please sign in to comment.