Trait EnterPolarsExt

Source
pub trait EnterPolarsExt {
    // Required method
    fn enter_polars<T, E, F>(self, f: F) -> PyResult<T>
       where F: Ungil + Send + FnOnce() -> Result<T, E>,
             T: Ungil + Send,
             E: Ungil + Send + Into<PyPolarsErr>;

    // Provided methods
    fn enter_polars_ok<T, F>(self, f: F) -> PyResult<T>
       where Self: Sized,
             F: Ungil + Send + FnOnce() -> T,
             T: Ungil + Send { ... }
    fn enter_polars_df<F>(self, f: F) -> PyResult<PyDataFrame>
       where Self: Sized,
             F: Ungil + Send + FnOnce() -> PolarsResult<DataFrame> { ... }
    fn enter_polars_series<T, F>(self, f: F) -> PyResult<PySeries>
       where Self: Sized,
             T: Ungil + Send + IntoSeries,
             F: Ungil + Send + FnOnce() -> PolarsResult<T> { ... }
}

Required Methods§

Source

fn enter_polars<T, E, F>(self, f: F) -> PyResult<T>
where F: Ungil + Send + FnOnce() -> Result<T, E>, T: Ungil + Send, E: Ungil + Send + Into<PyPolarsErr>,

Whenever you have a block of code in the public Python API that (potentially) takes a long time, wrap it in enter_polars. This will ensure we release the GIL and catch KeyboardInterrupts.

This not only can increase performance and usability, it can avoid deadlocks on the GIL for Python UDFs.

Provided Methods§

Source

fn enter_polars_ok<T, F>(self, f: F) -> PyResult<T>
where Self: Sized, F: Ungil + Send + FnOnce() -> T, T: Ungil + Send,

Same as enter_polars, but wraps the result in PyResult::Ok, useful shorthand for infallible functions.

Source

fn enter_polars_df<F>(self, f: F) -> PyResult<PyDataFrame>
where Self: Sized, F: Ungil + Send + FnOnce() -> PolarsResult<DataFrame>,

Same as enter_polars, but expects a PolarsResult as return which is converted to a PyDataFrame.

Source

fn enter_polars_series<T, F>(self, f: F) -> PyResult<PySeries>
where Self: Sized, T: Ungil + Send + IntoSeries, F: Ungil + Send + FnOnce() -> PolarsResult<T>,

Same as enter_polars, but expects a PolarsResult as return which is converted to a PySeries through S: IntoSeries.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl EnterPolarsExt for Python<'_>

Source§

fn enter_polars<T, E, F>(self, f: F) -> PyResult<T>
where F: Ungil + Send + FnOnce() -> Result<T, E>, T: Ungil + Send, E: Ungil + Send + Into<PyPolarsErr>,

Implementors§