mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 11:55:55 +02:00
Refactor drop columns
to fix issues (#10903)
# Description This PR refactors `drop columns` and fixes issues #10902 and #6846. Tables with "holes" are now handled consistently, although still somewhat awkwardly. That is, the columns in the first row are used to determine which columns to drop, meaning that the columns displayed all the way to the right by `table` may not be the columns actually being dropped. For example, `[{a: 1}, {b: 2}] | drop column` will drop column `a` instead of `b`. Before, this would give a list of empty records. # User-Facing Changes `drop columns` can now take records as input.
This commit is contained in:
@ -93,3 +93,45 @@ fn fail_on_non_iterator() {
|
||||
|
||||
assert!(actual.err.contains("command doesn't support"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disjoint_columns_first_row_becomes_empty() {
|
||||
let actual = nu!(pipeline(
|
||||
"
|
||||
[{a: 1}, {b: 2, c: 3}]
|
||||
| drop column
|
||||
| columns
|
||||
| to nuon
|
||||
"
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[b, c]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn disjoint_columns() {
|
||||
let actual = nu!(pipeline(
|
||||
"
|
||||
[{a: 1, b: 2}, {c: 3}]
|
||||
| drop column
|
||||
| columns
|
||||
| to nuon
|
||||
"
|
||||
));
|
||||
|
||||
assert_eq!(actual.out, "[a, c]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record() {
|
||||
let actual = nu!("{a: 1, b: 2} | drop column | to nuon");
|
||||
|
||||
assert_eq!(actual.out, "{a: 1}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn more_columns_than_record_has() {
|
||||
let actual = nu!("{a: 1, b: 2} | drop column 3 | to nuon");
|
||||
|
||||
assert_eq!(actual.out, "{}");
|
||||
}
|
||||
|
Reference in New Issue
Block a user