nushell/crates/nu-command/src/commands
Andrés N. Robalino 5d59234f8d
Flexibility updating table's cells. (#4027)
Very often we need to work with tables (say extracted from unstructured data or some
kind of final report, timeseries, and the like).

It's inevitable we will be having columns that we can't know beforehand what their names
will be, or how many.

Also, we may end up with certain cells having values we may want to remove as we explore.

Here, `update cells` fundamentally goes over every cell in the table coming in and updates
the cell's contents with the output of the block passed. Basic example here:

```
> [

    [   ty1,       t2,       ty];

    [     1,        a, $nothing]
    [(wrap), (0..<10),      1Mb]
    [    1s,     ({}),  1000000]
    [ $true,   $false,   ([[]])]

] | update cells { describe }

───┬───────────────────────┬───────────────────────────┬──────────
 # │          ty1          │            t2             │    ty
───┼───────────────────────┼───────────────────────────┼──────────
 0 │ integer               │ string                    │ nothing
 1 │ row Column(table of ) │ range[[integer, integer)] │ filesize
 2 │ string                │ nothing                   │ integer
 3 │ boolean               │ boolean                   │ table of
───┴───────────────────────┴───────────────────────────┴──────────
```

and another one (in the examples) for cases, say we have a timeseries table generated and
we want to remove the zeros and have empty strings and save it out to something like CSV.

```
> [
    [2021-04-16, 2021-06-10, 2021-09-18, 2021-10-15, 2021-11-16, 2021-11-17, 2021-11-18];
    [        37,          0,          0,          0,         37,          0,          0]
] | update cells {|value| i
  if ($value | into int) == 0 {
    ""
  } {
    $value
  }
}

───┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────┬────────────
 # │ 2021-04-16 │ 2021-06-10 │ 2021-09-18 │ 2021-10-15 │ 2021-11-16 │ 2021-11-17 │ 2021-11-18
───┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────┼────────────
 0 │         37 │            │            │            │         37 │            │
───┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────┴────────────
```
2021-09-19 15:37:54 -05:00
..
charting Allow different names for ...rest (#3954) 2021-08-27 05:58:53 +12:00
config Begin directory contrib docs and split commands (#3650) 2021-06-19 12:06:44 +12:00
conversions Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
core_commands Fix #3090: let binding in command leaks when error occurs (#4022) 2021-09-19 14:57:20 +12:00
dataframe Update to polars 0.16 (#4013) 2021-09-16 07:10:12 +12:00
env Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
filesystem Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
filters Flexibility updating table's cells. (#4027) 2021-09-19 15:37:54 -05:00
formats Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
generators Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
math Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
network Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
path Path commands: Put column path args behid flag; Allow path join appending without flag (#4008) 2021-09-15 21:03:51 +03:00
pathvar Support other variables than PATH in pathvar (2nd attempt) (#3828) 2021-07-24 11:44:36 -05:00
platform Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
random Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
shells add command g to switch shell quickly (#4014) 2021-09-17 10:39:14 +01:00
strings Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
system Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
viewers Add general refactorings (#3996) 2021-09-10 10:44:22 +12:00
mod.rs Flexibility updating table's cells. (#4027) 2021-09-19 15:37:54 -05:00