mirror of
https://github.com/Magnus167/rustframe.git
synced 2025-08-21 10:40:01 +00:00
Compare commits
No commits in common. "ff4535c56bb91a61a9fc985c0038251485f35003" and "fe666a4ddbc96fc095c2563e3983041d5b8ab730" have entirely different histories.
ff4535c56b
...
fe666a4ddb
@ -252,28 +252,9 @@ impl DataFrame {
|
|||||||
old_name
|
old_name
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
let new_name_clone = new_name.clone();
|
self.data.insert(new_name.clone(), column);
|
||||||
self.data.insert(new_name, column);
|
|
||||||
if let Some(pos) = self.column_names.iter().position(|n| n == old_name) {
|
if let Some(pos) = self.column_names.iter().position(|n| n == old_name) {
|
||||||
self.column_names[pos] = new_name_clone.clone();
|
self.column_names[pos] = new_name;
|
||||||
}
|
|
||||||
|
|
||||||
// rename the column in the underlying Frame as well
|
|
||||||
if let Some(col) = self.data.get_mut(&new_name_clone) {
|
|
||||||
match col {
|
|
||||||
DataFrameColumn::F64(frame) => {
|
|
||||||
frame.rename(old_name, new_name_clone.clone());
|
|
||||||
}
|
|
||||||
DataFrameColumn::I64(frame) => {
|
|
||||||
frame.rename(old_name, new_name_clone.clone());
|
|
||||||
}
|
|
||||||
DataFrameColumn::String(frame) => {
|
|
||||||
frame.rename(old_name, new_name_clone.clone());
|
|
||||||
}
|
|
||||||
DataFrameColumn::Bool(frame) => {
|
|
||||||
frame.rename(old_name, new_name_clone.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,18 +232,11 @@ impl<T: Clone + PartialEq> Frame<T> {
|
|||||||
}
|
}
|
||||||
(RowIndex::Date(vals), RowIndexLookup::Date(lookup))
|
(RowIndex::Date(vals), RowIndexLookup::Date(lookup))
|
||||||
}
|
}
|
||||||
Some(RowIndex::Range(ref r)) => {
|
Some(RowIndex::Range(_)) => {
|
||||||
// If the length of the range does not match the number of rows, panic.
|
|
||||||
if r.end.saturating_sub(r.start) != num_rows {
|
|
||||||
panic!(
|
panic!(
|
||||||
"Frame::new: Range index length ({}) mismatch matrix rows ({})",
|
"Frame::new: Cannot explicitly provide a Range index. Use None for default range."
|
||||||
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.
|
||||||
(RowIndex::Range(0..num_rows), RowIndexLookup::None)
|
(RowIndex::Range(0..num_rows), RowIndexLookup::None)
|
||||||
@ -1136,10 +1129,10 @@ mod tests {
|
|||||||
Frame::new(matrix, vec!["X", "Y"], Some(index));
|
Frame::new(matrix, vec!["X", "Y"], Some(index));
|
||||||
}
|
}
|
||||||
#[test]
|
#[test]
|
||||||
#[should_panic(expected = "Frame::new: Range index length (4) mismatch matrix rows (3)")]
|
#[should_panic(expected = "Cannot explicitly provide a Range index")]
|
||||||
fn frame_new_panic_invalid_explicit_range_index() {
|
fn frame_new_panic_explicit_range() {
|
||||||
let matrix = create_test_matrix_f64(); // 3 rows
|
let matrix = create_test_matrix_f64();
|
||||||
let index = RowIndex::Range(0..4); // Range 0..4 but only 3 rows
|
let index = RowIndex::Range(0..3); // User cannot provide Range directly
|
||||||
Frame::new(matrix, vec!["A", "B"], Some(index));
|
Frame::new(matrix, vec!["A", "B"], Some(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user