diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index b5484841ae00..75a17453613e 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -4342,12 +4342,22 @@ def to_torch(self) -> torch.Tensor: # tensor.rename(self.name) return tensor - def to_arrow(self) -> pa.Array: + def to_arrow(self, *, future: bool = False) -> pa.Array: """ Return the underlying Arrow array. If the Series contains only a single chunk this operation is zero copy. + Parameters + ---------- + future + Setting this to `True` will write Polars' internal data structures that + might not be available by other Arrow implementations. + + .. warning:: + This functionality is considered **unstable**. It may be changed + at any point without it being considered a breaking change. + Examples -------- >>> s = pl.Series("a", [1, 2, 3]) @@ -4360,7 +4370,7 @@ def to_arrow(self) -> pa.Array: 3 ] """ - return self._s.to_arrow() + return self._s.to_arrow(future) def to_pandas( self, *, use_pyarrow_extension_array: bool = False, **kwargs: Any diff --git a/py-polars/src/series/export.rs b/py-polars/src/series/export.rs index 3478a1022272..d49f3358cc14 100644 --- a/py-polars/src/series/export.rs +++ b/py-polars/src/series/export.rs @@ -145,12 +145,12 @@ impl PySeries { /// Return the underlying Arrow array. #[allow(clippy::wrong_self_convention)] - fn to_arrow(&mut self) -> PyResult { + fn to_arrow(&mut self, future: bool) -> PyResult { self.rechunk(true); Python::with_gil(|py| { let pyarrow = py.import_bound("pyarrow")?; - interop::arrow::to_py::to_py_array(self.series.to_arrow(0, false), py, &pyarrow) + interop::arrow::to_py::to_py_array(self.series.to_arrow(0, future), py, &pyarrow) }) } }