Path: blob/main/crates/polars-python/src/lazyframe/exitable.rs
7889 views
use polars::prelude::*;1use pyo3::prelude::*;23use super::PyLazyFrame;4use crate::PyDataFrame;5use crate::utils::EnterPolarsExt;67#[pymethods]8#[cfg(not(target_arch = "wasm32"))]9impl PyLazyFrame {10fn collect_concurrently(&self, py: Python) -> PyResult<PyInProcessQuery> {11let ipq = py.enter_polars(|| {12let ldf = self.ldf.read().clone();13ldf.collect_concurrently()14})?;15Ok(PyInProcessQuery { ipq })16}17}1819#[pyclass(frozen)]20#[cfg(not(target_arch = "wasm32"))]21#[repr(transparent)]22#[derive(Clone)]23pub struct PyInProcessQuery {24pub ipq: InProcessQuery,25}2627#[pymethods]28#[cfg(not(target_arch = "wasm32"))]29impl PyInProcessQuery {30pub fn cancel(&self, py: Python) -> PyResult<()> {31py.enter_polars_ok(|| self.ipq.cancel())32}3334pub fn fetch(&self, py: Python) -> PyResult<Option<PyDataFrame>> {35let out = py.enter_polars(|| self.ipq.fetch().transpose())?;36Ok(out.map(|df| df.into()))37}3839pub fn fetch_blocking(&self, py: Python) -> PyResult<PyDataFrame> {40let out = py.enter_polars(|| self.ipq.fetch_blocking())?;41Ok(out.into())42}43}444546