From 092a7b7ccedba515a01e54e33d360206948d2756 Mon Sep 17 00:00:00 2001 From: Palash Tyagi <23239946+Magnus167@users.noreply.github.com> Date: Sun, 22 Jun 2025 05:08:05 +0100 Subject: [PATCH] Validate range index length in Frame::new to prevent mismatches with matrix rows --- src/frame/base.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/frame/base.rs b/src/frame/base.rs index daad7ee..4963dc5 100644 --- a/src/frame/base.rs +++ b/src/frame/base.rs @@ -232,10 +232,17 @@ impl Frame { } (RowIndex::Date(vals), RowIndexLookup::Date(lookup)) } - Some(RowIndex::Range(_)) => { - panic!( - "Frame::new: Cannot explicitly provide a Range index. Use None for default 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: 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.