From e921413c7486fe68a3511c9bfee133f54ad6e4d6 Mon Sep 17 00:00:00 2001 From: Alex Letkemann <73347343+letkemann@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:02:59 +0100 Subject: [PATCH 1/2] fix: Copy height in .vstack() for empty dataframes (#19641) --- crates/polars-core/src/frame/mod.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/polars-core/src/frame/mod.rs b/crates/polars-core/src/frame/mod.rs index 5c3fcac02207..7f34e7d947fd 100644 --- a/crates/polars-core/src/frame/mod.rs +++ b/crates/polars-core/src/frame/mod.rs @@ -1084,6 +1084,7 @@ impl DataFrame { self.width(), other.width(), ); self.columns.clone_from(&other.columns); + self.height = other.height; return Ok(self); } @@ -3567,6 +3568,21 @@ mod test { assert_eq!(df.first_col_n_chunks(), 2) } + #[test] + fn test_vstack_on_empty_dataframe() { + let mut df = DataFrame::empty(); + + let df_data = df! { + "flt" => [1., 1., 2., 2., 3., 3.], + "int" => [1, 1, 2, 2, 3, 3, ], + "str" => ["a", "a", "b", "b", "c", "c"] + } + .unwrap(); + + df.vstack_mut(&df_data).unwrap(); + assert_eq!(df.height, 6) + } + #[test] #[cfg(feature = "zip_with")] #[cfg_attr(miri, ignore)] From c1d485ea8a235212b97ffe40d8320b7ef4f7e8be Mon Sep 17 00:00:00 2001 From: Alex Letkemann <73347343+letkemann@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:08:55 +0100 Subject: [PATCH 2/2] refactor: formatting --- crates/polars-core/src/frame/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/polars-core/src/frame/mod.rs b/crates/polars-core/src/frame/mod.rs index 7f34e7d947fd..31083f42dfdd 100644 --- a/crates/polars-core/src/frame/mod.rs +++ b/crates/polars-core/src/frame/mod.rs @@ -3570,8 +3570,8 @@ mod test { #[test] fn test_vstack_on_empty_dataframe() { - let mut df = DataFrame::empty(); - + let mut df = DataFrame::empty(); + let df_data = df! { "flt" => [1., 1., 2., 2., 3., 3.], "int" => [1, 1, 2, 2, 3, 3, ],