From a6a37eff1ac65fe8935aef960e53902f9db7f041 Mon Sep 17 00:00:00 2001 From: Ritchie Vink Date: Mon, 28 Oct 2024 08:45:49 +0100 Subject: [PATCH] Pyo3Polars 0.18/0.11 -> Rust Polars 0.44 (#114) --- Cargo.toml | 12 ++++++------ example/derive_expression/expression_lib/Cargo.toml | 2 +- .../extend_polars/Cargo.toml | 2 +- .../extend_polars/src/parallel_jaccard_mod.rs | 3 ++- example/io_plugin/io_plugin/Cargo.toml | 2 +- example/io_plugin/io_plugin/src/lib.rs | 1 + pyo3-polars-derive/Cargo.toml | 2 +- pyo3-polars/Cargo.toml | 6 +++--- pyo3-polars/src/types.rs | 11 +++++++---- 9 files changed, 23 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 531b4f8..7e232e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,15 +9,15 @@ members = [ ] [workspace.dependencies] -polars = { version = "0.43.0", default-features = false } -polars-core = { version = "0.43.0", default-features = false } -polars-ffi = { version = "0.43.0", default-features = false } -polars-plan = { version = "0.43.0", default-feautres = false } -polars-lazy = { version = "0.43.0", default-features = false } +polars = { version = "0.44.0", default-features = false } +polars-core = { version = "0.44.0", default-features = false } +polars-ffi = { version = "0.44.0", default-features = false } +polars-plan = { version = "0.44.0", default-feautres = false } +polars-lazy = { version = "0.44.0", default-features = false } [workspace.dependencies.arrow] package = "polars-arrow" -version = "0.43.0" +version = "0.44.0" path = "../polars/crates/polars-arrow" default-features = false diff --git a/example/derive_expression/expression_lib/Cargo.toml b/example/derive_expression/expression_lib/Cargo.toml index 3fc8ac3..23dc2e7 100644 --- a/example/derive_expression/expression_lib/Cargo.toml +++ b/example/derive_expression/expression_lib/Cargo.toml @@ -10,7 +10,7 @@ crate-type = ["cdylib"] [dependencies] polars = { workspace = true, features = ["fmt", "dtype-date", "timezones"], default-features = false } -pyo3 = { version = "0.22.2", features = ["abi3-py38"] } +pyo3 = { version = "0.21", features = ["abi3-py38"] } pyo3-polars = { version = "*", path = "../../../pyo3-polars", features = ["derive"] } rayon = "1.7.0" serde = { version = "1", features = ["derive"] } diff --git a/example/extend_polars_python_dispatch/extend_polars/Cargo.toml b/example/extend_polars_python_dispatch/extend_polars/Cargo.toml index b4f6c0c..d24467e 100644 --- a/example/extend_polars_python_dispatch/extend_polars/Cargo.toml +++ b/example/extend_polars_python_dispatch/extend_polars/Cargo.toml @@ -12,6 +12,6 @@ crate-type = ["cdylib"] polars = { workspace = true, features = ["fmt"] } polars-core = { workspace = true } polars-lazy = { workspace = true } -pyo3 = { version = "0.22.2", features = ["extension-module"] } +pyo3 = { version = "0.21", features = ["extension-module"] } pyo3-polars = { version = "*", path = "../../../pyo3-polars", features = ["lazy"] } rayon = "1.10" diff --git a/example/extend_polars_python_dispatch/extend_polars/src/parallel_jaccard_mod.rs b/example/extend_polars_python_dispatch/extend_polars/src/parallel_jaccard_mod.rs index c9e99d1..69f8544 100644 --- a/example/extend_polars_python_dispatch/extend_polars/src/parallel_jaccard_mod.rs +++ b/example/extend_polars_python_dispatch/extend_polars/src/parallel_jaccard_mod.rs @@ -64,7 +64,8 @@ pub(super) fn parallel_jaccard(df: DataFrame, col_a: &str, col_b: &str) -> Polar let a = sub_df.column(col_a)?; let b = sub_df.column(col_b)?; - let out = compute_jaccard_similarity(a, b)?; + let out = + compute_jaccard_similarity(a.as_materialized_series(), b.as_materialized_series())?; df!( "jaccard" => out diff --git a/example/io_plugin/io_plugin/Cargo.toml b/example/io_plugin/io_plugin/Cargo.toml index 471926b..c611040 100644 --- a/example/io_plugin/io_plugin/Cargo.toml +++ b/example/io_plugin/io_plugin/Cargo.toml @@ -10,6 +10,6 @@ crate-type = ["cdylib"] [dependencies] polars = { workspace = true, features = ["fmt", "dtype-date", "timezones", "lazy"], default-features = false } -pyo3 = { version = "0.22.2", features = ["abi3-py38"] } +pyo3 = { version = "0.21", features = ["abi3-py38"] } pyo3-polars = { version = "*", path = "../../../pyo3-polars", features = ["derive", "lazy"] } rand = { version = "0.8.5", features = [] } diff --git a/example/io_plugin/io_plugin/src/lib.rs b/example/io_plugin/io_plugin/src/lib.rs index 54c11b7..4933828 100644 --- a/example/io_plugin/io_plugin/src/lib.rs +++ b/example/io_plugin/io_plugin/src/lib.rs @@ -85,6 +85,7 @@ impl RandomSource { // Apply slice pushdown. // This prevents unneeded sampling. s.next_n(std::cmp::min(self.size_hint, self.n_rows)) + .into_column() }) .collect::>(); diff --git a/pyo3-polars-derive/Cargo.toml b/pyo3-polars-derive/Cargo.toml index b9f5059..2b685b2 100644 --- a/pyo3-polars-derive/Cargo.toml +++ b/pyo3-polars-derive/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-polars-derive" -version = "0.11.0" +version = "0.12.0" edition = "2021" license = "MIT" readme = "README.md" diff --git a/pyo3-polars/Cargo.toml b/pyo3-polars/Cargo.toml index 3115782..06e613e 100644 --- a/pyo3-polars/Cargo.toml +++ b/pyo3-polars/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pyo3-polars" -version = "0.17.0" +version = "0.18.0" edition = "2021" license = "MIT" readme = "../README.md" @@ -18,8 +18,8 @@ polars-core = { workspace = true, default-features = false } polars-ffi = { workspace = true, optional = true } polars-lazy = { workspace = true, optional = true } polars-plan = { workspace = true, optional = true } -pyo3 = "0.22.2" -pyo3-polars-derive = { version = "0.11.0", path = "../pyo3-polars-derive", optional = true } +pyo3 = "0.21" +pyo3-polars-derive = { version = "0.12.0", path = "../pyo3-polars-derive", optional = true } serde = { version = "1", optional = true } serde-pickle = { version = "1", optional = true } thiserror = "1" diff --git a/pyo3-polars/src/types.rs b/pyo3-polars/src/types.rs index 743d0c4..c7ad060 100644 --- a/pyo3-polars/src/types.rs +++ b/pyo3-polars/src/types.rs @@ -191,9 +191,13 @@ impl<'a> FromPyObject<'a> for PyDataFrame { for pyseries in series.iter()? { let pyseries = pyseries?; let s = pyseries.extract::()?.0; - columns.push(s); + columns.push(s.into_column()); + } + unsafe { + Ok(PyDataFrame(DataFrame::new_no_checks_height_from_first( + columns, + ))) } - unsafe { Ok(PyDataFrame(DataFrame::new_no_checks(columns))) } } } @@ -304,7 +308,7 @@ impl IntoPy for PyDataFrame { .0 .get_columns() .iter() - .map(|s| PySeries(s.clone()).into_py(py)) + .map(|s| PySeries(s.as_materialized_series().clone()).into_py(py)) .collect::>(); let polars = POLARS.bind(py); @@ -508,7 +512,6 @@ impl<'py> FromPyObject<'py> for PyDataType { fn extract_bound(ob: &Bound<'py, PyAny>) -> PyResult { let py = ob.py(); let type_name = ob.get_type().qualname()?; - let type_name = type_name.to_cow()?; let dtype = match type_name.as_ref() { "DataTypeClass" => {