From f3bcfc0e0096df9511ee5bcdc97c76732d7e2d61 Mon Sep 17 00:00:00 2001 From: Peter Bower <37089506+pbower@users.noreply.github.com> Date: Sun, 11 Oct 2026 00:49:46 +0100 Subject: [PATCH] Keep the selection order when a column selection covers every column --- src/structs/table.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/structs/table.rs b/src/structs/table.rs index e870415..48f04ad 100644 --- a/src/structs/table.rs +++ b/src/structs/table.rs @@ -1258,8 +1258,8 @@ impl ColumnSelection for Table { let all_fields: Vec> = self.cols.iter().map(|fa| fa.field.clone()).collect(); let col_indices = selection.resolve_fields(&all_fields); - // If selecting all columns, create a full view without filtering - if col_indices.len() == all_fields.len() { + // If selecting all columns in table order, create a full view without filtering + if col_indices.iter().copied().eq(0..all_fields.len()) { return TableV { name: self.name.clone(), fields: all_fields, @@ -1577,6 +1577,19 @@ mod tests { } } + #[cfg(all(feature = "views", feature = "select"))] + #[test] + fn test_column_selection_of_every_column_keeps_the_selection_order() { + let mut t = Table::new_empty(); + t.add_col(fa_i32!("ints", 1, 2)); + t.add_col(fa_bool!("bools", true, false)); + + let view = t.c(vec!["bools", "ints"]); + let names: Vec<&str> = view.fields.iter().map(|f| f.name.as_str()).collect(); + assert_eq!(names, ["bools", "ints"]); + assert!(matches!(&view.col_ix(0).unwrap().array, Array::BooleanArray(_))); + } + #[test] #[should_panic(expected = "Column length mismatch")] fn test_column_length_mismatch_panics() {