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

fix(python): Fix Series.to_numpy for Array types with nulls and nested Arrays #16230

Merged
merged 8 commits into from
May 16, 2024

Conversation

stinodego
Copy link
Member

@stinodego stinodego commented May 15, 2024

Closes #14268

Changes

  • Move handling of Array types in Series.to_numpy to Rust
  • Fix handling of null values (see linked issue)
  • Fix handling of nested arrays

@github-actions github-actions bot added fix Bug fix python Related to Python Polars labels May 15, 2024
@stinodego stinodego changed the title fix(python): Fix Series.to_numpy for Array types with nulls fix(python): Fix Series.to_numpy for Array types with nulls and nested Arrays May 15, 2024
@stinodego stinodego marked this pull request as ready for review May 15, 2024 14:32
Copy link

codecov bot commented May 15, 2024

Codecov Report

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

Project coverage is 80.80%. Comparing base (15f6b36) to head (c464493).
Report is 17 commits behind head on main.

Files Patch % Lines
py-polars/src/series/export.rs 77.77% 4 Missing ⚠️
py-polars/src/to_numpy.rs 98.59% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16230      +/-   ##
==========================================
- Coverage   80.85%   80.80%   -0.06%     
==========================================
  Files        1394     1393       -1     
  Lines      179955   179388     -567     
  Branches     2909     2921      +12     
==========================================
- Hits       145508   144958     -550     
+ Misses      33942    33927      -15     
+ Partials      505      503       -2     

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

@stinodego stinodego requested a review from orlp as a code owner May 16, 2024 10:56
let chunks: Vec<_> = self.downcast_iter().map(|c| c.values().clone()).collect();

// SAFETY: Data type of arrays matches because they are chunks from the same array.
unsafe { Series::from_chunks_and_dtype_unchecked(self.name(), chunks, &self.inner_dtype()) }
Copy link
Member Author

@stinodego stinodego May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seems to be no reason to use Series::_try_from_arrow_unchecked_with_md..

Series::from_chunks_and_dtype_unchecked preserves the data type, so it should also preserve any metadata present on that dtype.

@ritchie46 ritchie46 merged commit 11fe9d8 into main May 16, 2024
27 checks passed
@ritchie46 ritchie46 deleted the to-np-array branch May 16, 2024 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Series.to_numpy doesn't work for Array types with nulls
2 participants