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

Calling .vstack() on empty dataframe results in wrong shape #19641

Closed
2 tasks done
letkemann opened this issue Nov 5, 2024 · 0 comments · Fixed by #19642
Closed
2 tasks done

Calling .vstack() on empty dataframe results in wrong shape #19641

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

Comments

@letkemann
Copy link
Contributor

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

use polars::prelude::*;

fn main() {
    let df_empty = DataFrame::empty();
    let df_data = df!("data" => [1, 2, 3]).unwrap();
    let df = df_empty.vstack(&df_data).unwrap();

    println!("Shape: {:?}", df.shape()); // Shape: (0, 1)
    println!("{df}"); // panic
}

Log output

Shape: (0, 1)
thread 'main' panicked at /home/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/polars-core-0.44.2/src/fmt.rs:567:13:
The column lengths in the DataFrame are not equal.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Issue description

The height of the 'data' dataframe is not copied to the empty dataframe. This results in panic when trying to print the dataframe.

Expected behavior

The empty dataframe should take over the shape of the 'data' dataframe.
Output polars version 0.43.1:

shape: (3, 1)
┌──────┐
│ data │
│ ---  │
│ i32  │
╞══════╡
│ 1    │
│ 2    │
│ 3    │
└──────┘

### Installed versions

polars = { version = "0.44.2" }
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

Successfully merging a pull request may close this issue.

1 participant