Skip to content

Commit

Permalink
fix: Throw informative error for 0-width Array
Browse files Browse the repository at this point in the history
This not only affects the example given in the issue but also just provides a generally better error.

Fixes #18921.
  • Loading branch information
coastalwhite committed Sep 25, 2024
1 parent 2467b27 commit 65ff6fb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/polars-core/src/series/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ impl Series {
pub fn cast_with_options(&self, dtype: &DataType, options: CastOptions) -> PolarsResult<Self> {
use DataType as D;

if matches!(dtype, D::Array(_, width) if *width == 0) {
polars_bail!(InvalidOperation: "Arrays with 0 width are not yet supported");
}

let do_clone = match dtype {
D::Unknown(UnknownKind::Any) => true,
D::Unknown(UnknownKind::Int(_)) if self.dtype().is_integer() => true,
Expand Down

0 comments on commit 65ff6fb

Please sign in to comment.