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

Misleading ShapeError error message #19795

Open
2 tasks done
theidecke opened this issue Nov 14, 2024 · 0 comments
Open
2 tasks done

Misleading ShapeError error message #19795

theidecke opened this issue Nov 14, 2024 · 0 comments
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars

Comments

@theidecke
Copy link

theidecke commented Nov 14, 2024

Checks

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of Polars.

Reproducible example

Log output

No response

Issue description

When trying to create a DataFrame from two series with mismatching length this (rightfully) causes a ShapeError exception, whose error message currently reads something like:

polars.exceptions.ShapeError: could not create a new DataFrame: series 4321 has length 4321 while series "columnname" has length 4320

The issue is, that instead of the name of the first series, the length of the series is returned, but the wording implies that it's the name which is not helpful for debugging the error and can be confusing.

The relevant line in the source code is

columns[0].len(), height, col.name(), col.len()

where the surrounding code currently reads:

        let height = fst.len();
        for col in &columns[1..] {
            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()
            );
        }

My proposal is that instead it should be:

        let height = fst.len();
        for col in &columns[1..] {
            polars_ensure!(
                col.len() == height,
                ShapeMismatch: "could not create a new DataFrame: series {:?} has length {} while series {:?} has length {}",
                columns[0].name(), height, col.name(), col.len()
            );
        }

Expected behavior

The expected error message should instead read

polars.exceptions.ShapeError: could not create a new DataFrame: series "firstcolumnname" has length 4321 while series "columnname" has length 4320

Installed versions

1.13.1

@theidecke theidecke added bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars labels Nov 14, 2024
theidecke added a commit to theidecke/polars that referenced this issue Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Awaiting prioritization by a maintainer rust Related to Rust Polars
Projects
None yet
Development

No branches or pull requests

1 participant