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

perf(python): Avoid needless copy when converting chunked Series to NumPy #16178

Merged
merged 5 commits into from
May 13, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented May 12, 2024

Ref #14334

We used to always rechunk first when converting to NumPy. This is not great because:

  • If we go through the copy path (e.g. Series contains nulls), we iterate over the values anyway and rechunking is unnecessary.
  • If we go through the 'view' path (e.g. numeric Series without nulls), we do a copy (rechunk) but we end up with a non-writable array. Better to go through the copy path directly to ensure a writable array. Otherwise making the array writable is an additional copy.

Also changed some into_iter calls to iter.

@github-actions github-actions bot added performance Performance issues or improvements python Related to Python Polars labels May 12, 2024
Copy link

codecov bot commented May 12, 2024

Codecov Report

Attention: Patch coverage is 97.61905% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 80.98%. Comparing base (3892c75) to head (80a3d5d).

Files Patch % Lines
py-polars/polars/series/series.py 75.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16178      +/-   ##
==========================================
- Coverage   80.99%   80.98%   -0.02%     
==========================================
  Files        1387     1387              
  Lines      178832   178828       -4     
  Branches     2877     2876       -1     
==========================================
- Hits       144844   144821      -23     
- Misses      33496    33513      +17     
- Partials      492      494       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@stinodego stinodego marked this pull request as ready for review May 12, 2024 17:32
@ritchie46 ritchie46 merged commit 2adb030 into main May 13, 2024
19 checks passed
@ritchie46 ritchie46 deleted the to-np-refactor branch May 13, 2024 05:49
@c-peters c-peters added the accepted Ready for implementation label May 21, 2024
Wouittone pushed a commit to Wouittone/polars that referenced this pull request Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation performance Performance issues or improvements python Related to Python Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants