-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
387 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use crate::prelude::*; | ||
use polars_core::prelude::*; | ||
|
||
impl LazyFrame { | ||
pub fn scan_from_python_function(schema: Schema, scan_fn: Vec<u8>) -> Self { | ||
LogicalPlan::PythonScan { | ||
options: PythonOptions { | ||
scan_fn, | ||
schema: Arc::new(schema), | ||
..Default::default() | ||
}, | ||
} | ||
.into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
polars/polars-lazy/src/physical_plan/executors/python_scan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use super::*; | ||
use crate::prelude::*; | ||
use pyo3::prelude::*; | ||
use pyo3::types::PyBytes; | ||
|
||
pub(crate) struct PythonScanExec { | ||
pub(crate) options: PythonOptions, | ||
} | ||
|
||
impl Executor for PythonScanExec { | ||
fn execute(&mut self, _cache: &ExecutionState) -> Result<DataFrame> { | ||
let with_columns = self.options.with_columns.take(); | ||
Python::with_gil(|py| { | ||
let pl = PyModule::import(py, "polars").unwrap(); | ||
let pli = pl.getattr("internals").unwrap(); | ||
let deser_and_exec = pli.getattr("_deser_and_exec").unwrap(); | ||
|
||
let bytes = PyBytes::new(py, &self.options.scan_fn); | ||
|
||
let with_columns = | ||
with_columns.map(|mut cols| std::mem::take(Arc::make_mut(&mut cols))); | ||
|
||
let out = deser_and_exec | ||
.call1((bytes, with_columns)) | ||
.map_err(|err| PolarsError::ComputeError(format!("{:?}", err).into()))?; | ||
let pydf = out.getattr("_df").unwrap(); | ||
let raw_parts = pydf.call_method0("into_raw_parts").unwrap(); | ||
let raw_parts = raw_parts.extract::<(usize, usize, usize)>().unwrap(); | ||
|
||
let (ptr, len, cap) = raw_parts; | ||
unsafe { | ||
Ok(DataFrame::new_no_checks(Vec::from_raw_parts( | ||
ptr as *mut Series, | ||
len, | ||
cap, | ||
))) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.