polars.Series.to_numpy#

Series.to_numpy(
*args: Any,
zero_copy_only: bool = False,
writable: bool = False,
use_pyarrow: bool = True,
) ndarray[Any, Any][source]#

Convert this Series to numpy.

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.

Parameters:
*args

args will be sent to pyarrow.Array.to_numpy.

zero_copy_only

If True, an exception will be raised if the conversion to a numpy array would require copying the underlying data (e.g. in presence of nulls, or for non-primitive types).

writable

For numpy arrays created with zero copy (view on the Arrow data), the resulting array is not writable (Arrow data is immutable). By setting this to True, a copy of the array is made to ensure it is writable.

use_pyarrow

Use pyarrow.Array.to_numpy

for the conversion to numpy.

Examples

>>> s = pl.Series("a", [1, 2, 3])
>>> arr = s.to_numpy()
>>> arr  
array([1, 2, 3], dtype=int64)
>>> type(arr)
<class 'numpy.ndarray'>