mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-20 04:00:01 +00:00
Validate range index length in Frame::new to prevent mismatches with matrix rows
This commit is contained in:
parent
349ae52629
commit
092a7b7cce
@ -232,11 +232,18 @@ impl<T: Clone + PartialEq> Frame<T> {
|
||||
}
|
||||
(RowIndex::Date(vals), RowIndexLookup::Date(lookup))
|
||||
}
|
||||
Some(RowIndex::Range(_)) => {
|
||||
Some(RowIndex::Range(ref r)) => {
|
||||
// If the length of the range does not match the number of rows, panic.
|
||||
if r.end.saturating_sub(r.start) != num_rows {
|
||||
panic!(
|
||||
"Frame::new: Cannot explicitly provide a Range index. Use None for default range."
|
||||
"Frame::new: Range index length ({}) mismatch matrix rows ({})",
|
||||
r.end.saturating_sub(r.start),
|
||||
num_rows
|
||||
);
|
||||
}
|
||||
// return the range as is.
|
||||
(RowIndex::Range(r.clone()), RowIndexLookup::None)
|
||||
}
|
||||
None => {
|
||||
// Default to a sequential range index.
|
||||
(RowIndex::Range(0..num_rows), RowIndexLookup::None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user