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: Misleading ShapeError error message on dataframe creation #19901

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/polars-core/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl DataFrame {
polars_ensure!(
col.len() == height,
ShapeMismatch: "could not create a new DataFrame: series {:?} has length {} while series {:?} has length {}",
columns[0].len(), height, col.name(), col.len()
columns[0].name(), height, col.name(), col.len()
);
}

Expand Down
9 changes: 9 additions & 0 deletions py-polars/tests/unit/dataframe/test_df.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DuplicateError,
InvalidOperationError,
OutOfBoundsError,
ShapeError,
)
from polars.testing import (
assert_frame_equal,
Expand Down Expand Up @@ -2997,3 +2998,11 @@ def test_get_column_index() -> None:

with pytest.raises(ColumnNotFoundError, match="missing"):
df.get_column_index("missing")


def test_dataframe_creation_with_different_series_lengths_19795() -> None:
with pytest.raises(
ShapeError,
match='could not create a new DataFrame: series "a" has length 2 while series "b" has length 1',
):
pl.DataFrame({"a": [1, 2], "b": [1]})
Loading