polars.Series.to_numpy#
- Series.to_numpy(
- *,
- allow_copy: bool = True,
- writable: bool = False,
- use_pyarrow: bool = True,
- zero_copy_only: bool | None = None,
Convert this Series to a NumPy ndarray.
This operation may copy 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-copiedBooleans cannot be zero-copied
To ensure that no data is copied, set
allow_copy=False
.- Parameters:
- allow_copy
Allow memory to be copied to perform the conversion. If set to
False
, causes conversions that are not zero-copy to fail.- writable
Ensure the resulting array is writable. This will force a copy of the data if the array was created without copy, as the underlying Arrow data is immutable.
- use_pyarrow
Use pyarrow.Array.to_numpy for the conversion to NumPy.
- zero_copy_only
Raise an exception if the conversion to a NumPy would require copying the underlying data. Data copy occurs, for example, when the Series contains nulls or non-numeric types.
Deprecated since version 0.20.10: Use the
allow_copy
parameter instead, which is the inverse of this one.
Examples
>>> s = pl.Series("a", [1, 2, 3]) >>> arr = s.to_numpy() >>> arr array([1, 2, 3], dtype=int64) >>> type(arr) <class 'numpy.ndarray'>