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: Allow reshaping empty array to Array dtype #18876

Closed
wants to merge 1 commit into from

Conversation

hexane360
Copy link

Changes reshape logic to allow reshaping to a Series with Array dtype of length 0. Zero width arrays are still unsupported.

This is a rough draft, please let me know what you think.

Examples:

  pl.Series([]).reshape((0, 2)) => shape(0, 2) (used to error)
  pl.Series([]).reshape((-1, 2, 3)) => shape (0, 2, 3) (used to error)
  pl.Series([]).reshape((0, 0)) => InvalidOperationError("cannot reshape array into shape containing a zero dimension after the first")
  pl.Series([]).reshape((5, -1)) => InvalidOperationError("cannot reshape empty array into shape (5, -1)")

Some error messages are changed. Does polars consider that a breaking change? For instance, pl.Series([]).reshape((0, 0)) used to error with the message "cannot reshape empty array into shape (0, 0)".

Fixes #18369

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Sep 23, 2024
@hexane360
Copy link
Author

Another issue this may fix: #18598

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

Attention: Patch coverage is 93.33333% with 1 line in your changes missing coverage. Please review.

Project coverage is 79.86%. Comparing base (71a8b05) to head (47d670c).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
crates/polars-core/src/series/ops/reshape.rs 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #18876      +/-   ##
==========================================
- Coverage   79.88%   79.86%   -0.02%     
==========================================
  Files        1522     1522              
  Lines      206958   206955       -3     
  Branches     2906     2906              
==========================================
- Hits       165322   165294      -28     
- Misses      41088    41113      +25     
  Partials      548      548              

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

@hexane360 hexane360 force-pushed the reshape-empty-array branch 2 times, most recently from ec12237 to ebf1927 Compare September 26, 2024 18:36
@hexane360
Copy link
Author

Rebased against main

@coastalwhite
Copy link
Collaborator

This is now done by #18940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot initialize series with empty 2D numpy array
2 participants