New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor drop columns
to fix issues
#10903
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the refactor!
I am not sure what the expectations of folks are for jagged tables, so would be interested what folks expect. (In most of those cases reject
is probably preferrable for practical purposes)
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 | ||
" | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotta admit I find both of those behaviors absolutely cursed based on what the user sees with the default table
output.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lol, I agree. Perhaps we could:
- drop the first columns? Then it would be
skip columns
instead ofdrop columns
- compute the set of all columns (via
nu_engine::column::get_columns
). Unfortunately, this means we would have to collect theListStream
.
.input_output_types(vec![(Type::Table(vec![]), Type::Table(vec![]))]) | ||
.input_output_types(vec![ | ||
(Type::Table(vec![]), Type::Table(vec![])), | ||
(Type::Record(vec![]), Type::Record(vec![])), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Good catch!
Matches the general behavior of `Vec::drain` or `indexmap::IndexMap::drain`: - Drop the remaining elements (implementing the unstable `keep_rest()` would not be compatible with something like `indexmap`) - No `AsRef<[T]>` or `Drain::as_slice()` behavior as this would make layout assumptions. - `Drain: DoubleEndedIterator` Found useful in nushell#10903
Matches the general behavior of `Vec::drain` or `indexmap::IndexMap::drain`: - Drop the remaining elements (implementing the unstable `keep_rest()` would not be compatible with something like `indexmap`) - No `AsRef<[T]>` or `Drain::as_slice()` behavior as this would make layout assumptions. - `Drain: DoubleEndedIterator` Found useful in #10903
Compatible with `Vec::truncate` and `indexmap::IndexMap::truncate` Found useful in nushell#10903 for `drop column`
# Description Compatible with `Vec::truncate` and `indexmap::IndexMap::truncate` Found useful in #10903 for `drop column` # Tests + Formatting Doctest with the relevant edge-cases
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rerunning the failed job.
I think I don't want to block this based on the behavior on tables with holes for now.
Great that this PR unlocks records and moves us to the sane API.
We can close #6846 with this and keep #10902 open I think.
I think I would like to bias us to stream by default so we may have to live with the weird behavior. We could consider adding a flag that collects the table so you can get sane truncation for tables with sparse columns.
Matches the general behavior of `Vec::drain` or `indexmap::IndexMap::drain`: - Drop the remaining elements (implementing the unstable `keep_rest()` would not be compatible with something like `indexmap`) - No `AsRef<[T]>` or `Drain::as_slice()` behavior as this would make layout assumptions. - `Drain: DoubleEndedIterator` Found useful in nushell#10903
# Description Compatible with `Vec::truncate` and `indexmap::IndexMap::truncate` Found useful in nushell#10903 for `drop column` # Tests + Formatting Doctest with the relevant edge-cases
# Description This PR refactors `drop columns` and fixes issues nushell#10902 and nushell#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.
Matches the general behavior of `Vec::drain` or `indexmap::IndexMap::drain`: - Drop the remaining elements (implementing the unstable `keep_rest()` would not be compatible with something like `indexmap`) - No `AsRef<[T]>` or `Drain::as_slice()` behavior as this would make layout assumptions. - `Drain: DoubleEndedIterator` Found useful in nushell#10903
# Description Compatible with `Vec::truncate` and `indexmap::IndexMap::truncate` Found useful in nushell#10903 for `drop column` # Tests + Formatting Doctest with the relevant edge-cases
# Description This PR refactors `drop columns` and fixes issues nushell#10902 and nushell#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.
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 bytable
may not be the columns actually being dropped. For example,[{a: 1}, {b: 2}] | drop column
will drop columna
instead ofb
. Before, this would give a list of empty records.User-Facing Changes
drop columns
can now take records as input.