Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Series.to_numpy raises when zero_copy_only=True even when Series is empty #14274

Closed
2 tasks done
stinodego opened this issue Feb 5, 2024 · 0 comments · Fixed by #14275
Closed
2 tasks done

Series.to_numpy raises when zero_copy_only=True even when Series is empty #14274

stinodego opened this issue Feb 5, 2024 · 0 comments · Fixed by #14275
Assignees
Labels
A-interop-numpy Area: interoperability with NumPy bug Something isn't working P-low Priority: low python Related to Python Polars

Comments

@stinodego
Copy link
Member

stinodego commented Feb 5, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

s = pl.Series()
arr = s.to_numpy(use_pyarrow=False, zero_copy_only=True)

Log output

Traceback (most recent call last):
  File "/home/stijn/code/polars/py-polars/repro.py", line 21, in <module>
    arr2 = s.to_numpy(use_pyarrow=False, zero_copy_only=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stijn/code/polars/py-polars/polars/series/series.py", line 4397, in to_numpy
    raise_no_zero_copy()
  File "/home/stijn/code/polars/py-polars/polars/series/series.py", line 4344, in raise_no_zero_copy
    raise ValueError(msg)
ValueError: cannot return a zero-copy array

Issue description

I would think this should not raise, since we're not copying any data.

PyArrow also raises here though:

s = pl.Series()
arr = s.to_numpy(use_pyarrow=True, zero_copy_only=True)
# pyarrow.lib.ArrowInvalid: Needed to copy 1 chunks with 0 nulls, but zero_copy_only was True

Expected behavior

Same behavior as when zero_copy_only=False.

Installed versions

main

@stinodego stinodego added bug Something isn't working python Related to Python Polars P-low Priority: low A-interop-numpy Area: interoperability with NumPy labels Feb 5, 2024
@stinodego stinodego self-assigned this Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-interop-numpy Area: interoperability with NumPy bug Something isn't working P-low Priority: low python Related to Python Polars
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant