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

feat(python): Respect index order in DataFrame.to_numpy also for non-numeric frames #16390

Merged
merged 1 commit into from
May 22, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented May 22, 2024

vstack followed by a transpose will result in an F-contiguous array. column_stack creates a C-contiguous array. So we can use one or the other depending on the order requested by the user.

Structured arrays are both C and F contiguous since they are 1-dimensional.

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels May 22, 2024
@stinodego stinodego marked this pull request as ready for review May 22, 2024 07:02
Copy link

codecov bot commented May 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.39%. Comparing base (4375930) to head (8c24cd4).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16390      +/-   ##
==========================================
- Coverage   81.40%   81.39%   -0.01%     
==========================================
  Files        1408     1409       +1     
  Lines      184222   184507     +285     
  Branches     2960     2960              
==========================================
+ Hits       149965   150183     +218     
- Misses      33742    33809      +67     
  Partials      515      515              

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

@ritchie46
Copy link
Member

Have you benchmarked those? The transpose is free as that only changes the strides.

@stinodego
Copy link
Member Author

Have you benchmarked those? The transpose is free as that only changes the strides.

I have not benchmarked this - in this case it's a correctness issue:

The default order is Fortran and this path is unchanged (it uses vstack followed by transpose).

If the user explicitly asks for C order, we used to return a Fortran-contiguous array in this path. So that was incorrect or at least surprising. For this path, we now use the column_stack approach.

@stinodego stinodego merged commit 0a46613 into main May 22, 2024
18 checks passed
@stinodego stinodego deleted the to-np-stacking-order branch May 22, 2024 11:02
@c-peters c-peters added the accepted Ready for implementation label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted Ready for implementation enhancement New feature or an improvement of an existing feature python Related to Python Polars
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants