From e6ea7949ef70208a37af862b37d2ce3b99a7e0e9 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Wed, 26 Jul 2023 18:27:12 +0100 Subject: [PATCH] docs(python): clarify "clones data" in to_numpy (#10095) --- py-polars/polars/series/series.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index 3b4fbf31a14d..8353d19b1170 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -3635,9 +3635,18 @@ def to_numpy( use_pyarrow: bool = True, ) -> np.ndarray[Any, Any]: """ - Convert this Series to numpy. This operation clones data but is completely safe. + Convert this Series to numpy. - If you want a zero-copy view and know what you are doing, use `.view()`. + This operation may clone data but is completely safe. Note that: + + - data which is purely numeric AND without null values is not cloned; + - floating point ``nan`` values can be zero-copied; + - booleans can't be zero-copied. + + To ensure that no data is cloned, set ``zero_copy_only=True``. + + Alternatively, if you want a zero-copy view and know what you are doing, + use `.view()`. Parameters ----------