Validate range index length in Frame::new to prevent mismatches with matrix rows

This commit is contained in:
Palash Tyagi 2025-06-22 05:08:05 +01:00
parent 349ae52629
commit 092a7b7cce

View File

@ -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.