-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(rust): Fix height validation in
hstack_mut
was bypassed when ad…
…ding to empty frame (#21335)
- Loading branch information
1 parent
c0f345f
commit 9164d2c
Showing
7 changed files
with
167 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
use polars_error::{polars_bail, PolarsResult}; | ||
use polars_utils::aliases::{InitHashMaps, PlHashSet}; | ||
|
||
use super::column::Column; | ||
use super::DataFrame; | ||
|
||
impl DataFrame { | ||
/// Ensure all equal height and names are unique. | ||
/// | ||
/// An Ok() result indicates `columns` is a valid state for a DataFrame. | ||
pub fn validate_columns_slice(columns: &[Column]) -> PolarsResult<()> { | ||
if columns.len() <= 1 { | ||
return Ok(()); | ||
} | ||
|
||
if columns.len() <= 4 { | ||
// Too small to be worth spawning a hashmap for, this is at most 6 comparisons. | ||
for i in 0..columns.len() - 1 { | ||
let name = columns[i].name(); | ||
let height = columns[i].len(); | ||
|
||
for other in columns.iter().skip(i + 1) { | ||
if other.name() == name { | ||
polars_bail!(duplicate = name); | ||
} | ||
|
||
if other.len() != height { | ||
polars_bail!( | ||
ShapeMismatch: | ||
"height of column '{}' ({}) does not match height of column '{}' ({})", | ||
other.name(), other.len(), name, height | ||
) | ||
} | ||
} | ||
} | ||
} else { | ||
let first = &columns[0]; | ||
|
||
let first_len = first.len(); | ||
let first_name = first.name(); | ||
|
||
let mut names = PlHashSet::with_capacity(columns.len()); | ||
names.insert(first_name); | ||
|
||
for col in &columns[1..] { | ||
let col_name = col.name(); | ||
let col_len = col.len(); | ||
|
||
if col_len != first_len { | ||
polars_bail!( | ||
ShapeMismatch: | ||
"height of column '{}' ({}) does not match height of column '{}' ({})", | ||
col_name, col_len, first_name, first_len | ||
) | ||
} | ||
|
||
if names.contains(col_name) { | ||
polars_bail!(duplicate = col_name) | ||
} | ||
|
||
names.insert(col_name); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.