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,10 +232,17 @@ impl<T: Clone + PartialEq> Frame<T> {
|
|||||||
}
|
}
|
||||||
(RowIndex::Date(vals), RowIndexLookup::Date(lookup))
|
(RowIndex::Date(vals), RowIndexLookup::Date(lookup))
|
||||||
}
|
}
|
||||||
Some(RowIndex::Range(_)) => {
|
Some(RowIndex::Range(ref r)) => {
|
||||||
panic!(
|
// If the length of the range does not match the number of rows, panic.
|
||||||
"Frame::new: Cannot explicitly provide a Range index. Use None for default range."
|
if r.end.saturating_sub(r.start) != num_rows {
|
||||||
);
|
panic!(
|
||||||
|
"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 => {
|
None => {
|
||||||
// Default to a sequential range index.
|
// Default to a sequential range index.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user