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: Raise instead of panicking when casting a Series to a Struct with the wrong number of fields #21213

Merged
merged 4 commits into from
Feb 14, 2025

Conversation

etiennebacher
Copy link
Contributor

@etiennebacher etiennebacher commented Feb 12, 2025

Fixes #14083

The current behavior when casting a single series to a struct with multiple fields is to fill with nulls:

import polars as pl
print(
  pl.Series([1], dtype=pl.Int32).cast(pl.Struct({"a": pl.UInt8, "b": pl.UInt8}))
)
# shape: (1,)
# Series: '' [struct[2]]
# [
#        {1,null}
# ]

With this PR, this now throws an error but I don't know if that's considered a breaking change or a fix (the current behavior is untested).

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Feb 12, 2025
@etiennebacher etiennebacher changed the title fix: Raise instead of panicking when casting to a Struct with the wrong number of fields fix: Raise instead of panicking when casting a Series to a Struct with the wrong number of fields Feb 12, 2025
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 79.87%. Comparing base (515c1b8) to head (1d954a0).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21213      +/-   ##
==========================================
+ Coverage   79.80%   79.87%   +0.07%     
==========================================
  Files        1596     1596              
  Lines      228468   228469       +1     
  Branches     2607     2607              
==========================================
+ Hits       182318   182484     +166     
+ Misses      45554    45389     -165     
  Partials      596      596              

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

@ritchie46 ritchie46 merged commit 9077aa4 into pola-rs:main Feb 14, 2025
27 checks passed
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 rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cast to struct panics from invalid types
2 participants