diff --git a/py-polars/src/dataframe/export.rs b/py-polars/src/dataframe/export.rs index f595ac92f02c..cfd6f1406ef2 100644 --- a/py-polars/src/dataframe/export.rs +++ b/py-polars/src/dataframe/export.rs @@ -140,6 +140,6 @@ impl PyDataFrame { requested_schema: Option, ) -> PyResult> { self.df.align_chunks(); - dataframe_to_stream(self.df.clone(), py) + dataframe_to_stream(&self.df, py) } } diff --git a/py-polars/src/interop/arrow/to_py.rs b/py-polars/src/interop/arrow/to_py.rs index 17a89ff1eccc..2581a52f34ce 100644 --- a/py-polars/src/interop/arrow/to_py.rs +++ b/py-polars/src/interop/arrow/to_py.rs @@ -71,7 +71,10 @@ pub(crate) fn series_to_stream<'py>( PyCapsule::new_bound(py, stream, Some(stream_capsule_name)) } -pub(crate) fn dataframe_to_stream(df: DataFrame, py: Python) -> PyResult> { +pub(crate) fn dataframe_to_stream<'py>( + df: &'py DataFrame, + py: Python<'py>, +) -> PyResult> { let iter = Box::new(DataFrameStreamIterator::new(df)); let field = iter.field(); let stream = ffi::export_iterator(iter, field); @@ -87,7 +90,7 @@ pub struct DataFrameStreamIterator { } impl DataFrameStreamIterator { - fn new(df: DataFrame) -> Self { + fn new(df: &DataFrame) -> Self { let schema = df.schema().to_arrow(CompatLevel::newest()); let data_type = ArrowDataType::Struct(schema.fields);