From 8f8bcd5140473317aa7b4ad6e891636ef877e970 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 26 Jul 2023 14:53:30 +0100 Subject: [PATCH 1/4] docs(python): clarify "clones data" in to_numpy --- py-polars/Cargo.lock | 1 + py-polars/polars/series/series.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/py-polars/Cargo.lock b/py-polars/Cargo.lock index d093e9ebfc8c..895d3a7a2e1d 100644 --- a/py-polars/Cargo.lock +++ b/py-polars/Cargo.lock @@ -1699,6 +1699,7 @@ dependencies = [ "hashbrown 0.14.0", "num-traits", "once_cell", + "polars-error", "rayon", "smartstring", "sysinfo", diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index 3b4fbf31a14d..ad4e66d9b566 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -3635,8 +3635,10 @@ 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. + This operation clones data (unless `zero_copy_only=True`) + but is completely safe. If you want a zero-copy view and know what you are doing, use `.view()`. Parameters From 4c3a952aed64cc8e7fee8e2faa9605a3466b6de7 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:21:53 +0100 Subject: [PATCH 2/4] clarify nan and bool --- py-polars/polars/series/series.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index ad4e66d9b566..fe540fc317ed 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -3637,9 +3637,12 @@ def to_numpy( """ Convert this Series to numpy. - This operation clones data (unless `zero_copy_only=True`) - but is completely safe. - If you want a zero-copy view and know what you are doing, use `.view()`. + This operation clones data unless it is purely numeric with no null values. + Note that floating point ``nan`` values can be zero-copied, whereas as + booleans can't. 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 ---------- From 28d7b9cc1874707d56897413204e1910162606d0 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:25:12 +0100 Subject: [PATCH 3/4] correct --- py-polars/polars/series/series.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index fe540fc317ed..fbac548ccd38 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -3637,9 +3637,13 @@ def to_numpy( """ Convert this Series to numpy. - This operation clones data unless it is purely numeric with no null values. - Note that floating point ``nan`` values can be zero-copied, whereas as - booleans can't. To ensure that no data is cloned, set ``zero_copy_only=True``. + 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()`. From 5563561a2d414b6a30c0485a7ce7cfbe77b38501 Mon Sep 17 00:00:00 2001 From: MarcoGorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 26 Jul 2023 15:59:57 +0100 Subject: [PATCH 4/4] add blank line --- py-polars/polars/series/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/py-polars/polars/series/series.py b/py-polars/polars/series/series.py index fbac548ccd38..8353d19b1170 100644 --- a/py-polars/polars/series/series.py +++ b/py-polars/polars/series/series.py @@ -3637,8 +3637,8 @@ def to_numpy( """ Convert this Series to numpy. - This operation may clone data but is completely safe. - Note that: + 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.