Skip to content

UPSTREAM PR #17787: feat: group-by flag to delete column after grouping by it#116

Open
loci-dev wants to merge 3 commits into
mainfrom
loci/pr-17787-group-by-prune
Open

UPSTREAM PR #17787: feat: group-by flag to delete column after grouping by it#116
loci-dev wants to merge 3 commits into
mainfrom
loci/pr-17787-group-by-prune

Conversation

@loci-dev

Copy link
Copy Markdown

Note

Source pull request: nushell/nushell#17787

Release notes summary - What our users need to know

  • adds group-by --prune, which deletes the original column(s) it grouped by
  • only affects cell-path arguments. closure arguments are unaffected
  • if the parent becomes empty after pruning (because the column was nested), then the parent is also removed
> let table = [[name, meta]; [andres, {lang: rb, year: "2019"}], [jt, {lang: rs, year: "2019"}], [storm, {lang: rs, year: "2021"}], [kai, {lang: rb, year: "2021"}]]

> $table
╭───┬────────┬─────────────────╮
│ # │  name  │      meta       │
├───┼────────┼─────────────────┤
│ 0 │ andres │ ╭──────┬──────╮ │
│   │        │ │ lang │ rb   │ │
│   │        │ │ year │ 2019 │ │
│   │        │ ╰──────┴──────╯ │
│ 1 │ jt     │ ╭──────┬──────╮ │
│   │        │ │ lang │ rs   │ │
│   │        │ │ year │ 2019 │ │
│   │        │ ╰──────┴──────╯ │
│ 2 │ storm  │ ╭──────┬──────╮ │
│   │        │ │ lang │ rs   │ │
│   │        │ │ year │ 2021 │ │
│   │        │ ╰──────┴──────╯ │
│ 3 │ kai    │ ╭──────┬──────╮ │
│   │        │ │ lang │ rb   │ │
│   │        │ │ year │ 2021 │ │
│   │        │ ╰──────┴──────╯ │
╰───┴────────┴─────────────────╯
> $table | group-by meta.year --prune
╭──────┬────────────────────────────────╮
│      │ ╭───┬────────┬───────────────╮ │
│ 2019 │ │ # │  name  │     meta      │ │
│      │ ├───┼────────┼───────────────┤ │
│      │ │ 0 │ andres │ ╭──────┬────╮ │ │
│      │ │   │        │ │ lang │ rb │ │ │
│      │ │   │        │ ╰──────┴────╯ │ │
│      │ │ 1 │ jt     │ ╭──────┬────╮ │ │
│      │ │   │        │ │ lang │ rs │ │ │
│      │ │   │        │ ╰──────┴────╯ │ │
│      │ ╰───┴────────┴───────────────╯ │
│      │ ╭───┬───────┬───────────────╮  │
│ 2021 │ │ # │ name  │     meta      │  │
│      │ ├───┼───────┼───────────────┤  │
│      │ │ 0 │ storm │ ╭──────┬────╮ │  │
│      │ │   │       │ │ lang │ rs │ │  │
│      │ │   │       │ ╰──────┴────╯ │  │
│      │ │ 1 │ kai   │ ╭──────┬────╮ │  │
│      │ │   │       │ │ lang │ rb │ │  │
│      │ │   │       │ ╰──────┴────╯ │  │
│      │ ╰───┴───────┴───────────────╯  │
╰──────┴────────────────────────────────╯
> $table | group-by meta.year meta.lang --prune # also removes the parent if it's now empty
╭──────┬─────────────────────────╮
│      │ ╭────┬────────────────╮ │
│ 2019 │ │    │ ╭───┬────────╮ │ │
│      │ │ rb │ │ # │  name  │ │ │
│      │ │    │ ├───┼────────┤ │ │
│      │ │    │ │ 0 │ andres │ │ │
│      │ │    │ ╰───┴────────╯ │ │
│      │ │    │ ╭───┬──────╮   │ │
│      │ │ rs │ │ # │ name │   │ │
│      │ │    │ ├───┼──────┤   │ │
│      │ │    │ │ 0 │ jt   │   │ │
│      │ │    │ ╰───┴──────╯   │ │
│      │ ╰────┴────────────────╯ │
│      │ ╭────┬───────────────╮  │
│ 2021 │ │    │ ╭───┬───────╮ │  │
│      │ │ rs │ │ # │ name  │ │  │
│      │ │    │ ├───┼───────┤ │  │
│      │ │    │ │ 0 │ storm │ │  │
│      │ │    │ ╰───┴───────╯ │  │
│      │ │    │ ╭───┬──────╮  │  │
│      │ │ rb │ │ # │ name │  │  │
│      │ │    │ ├───┼──────┤  │  │
│      │ │    │ │ 0 │ kai  │  │  │
│      │ │    │ ╰───┴──────╯  │  │
│      │ ╰────┴───────────────╯  │
╰──────┴─────────────────────────╯

Motivation

for my use, I always want to delete the column after grouping.
the help text suggests update cells { reject column-name } for this, but I find this cumbersome.

feel free to suggest a better name for the flag.

@loci-dev loci-dev force-pushed the main branch 4 times, most recently from d6c3b3e to aa2e4e6 Compare March 18, 2026 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants