Skip to content

Commit

Permalink
pyo3-polars 0.13.0 (rust polars 0.39.0) (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 authored Apr 14, 2024
1 parent c04d471 commit 19146ab
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ members = [
]

[workspace.dependencies]
polars = { version = "0.38.0", default-features = false }
polars-core = { version = "0.38.0", default-features = false }
polars-ffi = { version = "0.38.0", default-features = false }
polars-plan = { version = "0.38.0", default-feautres = false }
polars-lazy = { version = "0.38.0", default-features = false }
polars = { version = "0.39.0", default-features = false }
polars-core = { version = "0.39.0", default-features = false }
polars-ffi = { version = "0.39.0", default-features = false }
polars-plan = { version = "0.39.0", default-feautres = false }
polars-lazy = { version = "0.39.0", default-features = false }
2 changes: 1 addition & 1 deletion example/derive_expression/expression_lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ crate-type = ["cdylib"]

[dependencies]
polars = { workspace = true, features = ["fmt", "dtype-date", "timezones"], default-features = false }
pyo3 = { version = "0.20", features = ["abi3-py38"] }
pyo3 = { version = "0.21", features = ["abi3-py38"] }
pyo3-polars = { version = "*", path = "../../../pyo3-polars", features = ["derive"] }
serde = { version = "1", features = ["derive"] }
rayon = "1.7.0"
Expand Down
1 change: 0 additions & 1 deletion example/derive_expression/expression_lib/src/distances.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use polars::datatypes::PlHashSet;
use polars::export::arrow::array::PrimitiveArray;
use polars::export::num::Float;
use polars::prelude::*;
Expand Down
8 changes: 5 additions & 3 deletions example/derive_expression/expression_lib/src/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,14 @@ fn convert_timezone(input_fields: &[Field], kwargs: TimeZone) -> PolarsResult<Fi
})
}

/// This expression is for demonstration purposes as we have a dedicated
/// `convert_time_zone` in Polars.
#[polars_expr(output_type_func_with_kwargs=convert_timezone)]
fn change_time_zone(input: &[Series], kwargs: TimeZone) -> PolarsResult<Series> {
let input = &input[0];
let ca = input.datetime()?;

ca.clone()
.convert_time_zone(kwargs.tz)
.map(|ca| ca.into_series())
let mut out = ca.clone();
out.set_time_zone(kwargs.tz)?;
Ok(out.into_series())
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ crate-type = ["cdylib"]
polars = { workspace = true, features = ["fmt"] }
polars-core = { workspace = true }
polars-lazy = { workspace = true }
pyo3 = { version = "0.20", features = ["extension-module"] }
pyo3 = { version = "0.21", features = ["extension-module"] }
pyo3-polars = { version = "*", path = "../../../pyo3-polars", features = ["lazy"] }
rayon = "1.6"
rayon = "1.10"
2 changes: 1 addition & 1 deletion pyo3-polars-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyo3-polars-derive"
version = "0.6.0"
version = "0.7.0"
edition = "2021"
license = "MIT"
readme = "README.md"
Expand Down
1 change: 1 addition & 0 deletions pyo3-polars-derive/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use syn::Token;

#[derive(Clone, Debug)]
pub struct KeyWordAttribute<K, V> {
#[allow(dead_code)]
pub kw: K,
pub value: V,
}
Expand Down
6 changes: 3 additions & 3 deletions pyo3-polars/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pyo3-polars"
version = "0.12.0"
version = "0.13.0"
edition = "2021"
license = "MIT"
readme = "../README.md"
Expand All @@ -16,8 +16,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.20.0"
pyo3-polars-derive = { version = "0.6.0", path = "../pyo3-polars-derive", optional = true }
pyo3 = "0.21.0"
pyo3-polars-derive = { version = "0.7.0", path = "../pyo3-polars-derive", optional = true }
serde = { version = "1", optional = true }
serde-pickle = { version = "1", optional = true }
thiserror = "1"
Expand Down
6 changes: 5 additions & 1 deletion pyo3-polars/src/ffi/to_py.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ use pyo3::ffi::Py_uintptr_t;
use pyo3::prelude::*;

/// Arrow array to Python.
pub(crate) fn to_py_array(array: ArrayRef, py: Python, pyarrow: &PyModule) -> PyResult<PyObject> {
pub(crate) fn to_py_array(
array: ArrayRef,
py: Python,
pyarrow: Bound<'_, PyModule>,
) -> PyResult<PyObject> {
let schema = Box::new(ffi::export_field_to_c(&ArrowField::new(
"",
array.data_type().clone(),
Expand Down
8 changes: 4 additions & 4 deletions pyo3-polars/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ use crate::ffi::to_py::to_py_array;
use polars::export::arrow;
use polars::prelude::*;
use pyo3::ffi::Py_uintptr_t;
use pyo3::{FromPyObject, IntoPy, PyAny, PyObject, PyResult, Python, ToPyObject};
use pyo3::prelude::*;

#[cfg(feature = "lazy")]
use {polars_lazy::frame::LazyFrame, polars_plan::logical_plan::LogicalPlan};
Expand Down Expand Up @@ -162,7 +162,7 @@ impl<'a> FromPyObject<'a> for PyLazyFrame {

impl IntoPy<PyObject> for PySeries {
fn into_py(self, py: Python<'_>) -> PyObject {
let polars = py.import("polars").expect("polars not installed");
let polars = py.import_bound("polars").expect("polars not installed");
let s = polars.getattr("Series").unwrap();
match s.getattr("_import_from_c") {
// Go via polars
Expand Down Expand Up @@ -208,7 +208,7 @@ impl IntoPy<PyObject> for PySeries {
let s = self.0.rechunk();
let name = s.name();
let arr = s.to_arrow(0, false);
let pyarrow = py.import("pyarrow").expect("pyarrow not installed");
let pyarrow = py.import_bound("pyarrow").expect("pyarrow not installed");

let arg = to_py_array(arr, py, pyarrow).unwrap();
let s = polars.call_method1("from_arrow", (arg,)).unwrap();
Expand All @@ -228,7 +228,7 @@ impl IntoPy<PyObject> for PyDataFrame {
.map(|s| PySeries(s.clone()).into_py(py))
.collect::<Vec<_>>();

let polars = py.import("polars").expect("polars not installed");
let polars = py.import_bound("polars").expect("polars not installed");
let df_object = polars.call_method1("DataFrame", (pyseries,)).unwrap();
df_object.into_py(py)
}
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[toolchain]
channel = "nightly-2023-10-12"
channel = "nightly-2024-03-28"

0 comments on commit 19146ab

Please sign in to comment.