Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions src/frame/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,17 @@
}
(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)

Check warning on line 245 in src/frame/base.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/base.rs#L243-L245

Added lines #L243 - L245 were not covered by tests
}
None => {
// Default to a sequential range index.
Expand Down Expand Up @@ -1117,10 +1124,10 @@
Frame::new(matrix, vec!["X", "Y"], Some(index));
}
#[test]
#[should_panic(expected = "Cannot explicitly provide a Range index")]
fn frame_new_panic_explicit_range() {
let matrix = create_test_matrix_f64();
let index = RowIndex::Range(0..3); // User cannot provide Range directly
#[should_panic(expected = "Frame::new: Range index length (4) mismatch matrix rows (3)")]
fn frame_new_panic_invalid_explicit_range_index() {
let matrix = create_test_matrix_f64(); // 3 rows
let index = RowIndex::Range(0..4); // Range 0..4 but only 3 rows
Frame::new(matrix, vec!["A", "B"], Some(index));
}

Expand Down
Loading