Skip to content

Soft rest arguments column path cohersions.#3016

Merged
andrasio merged 1 commit intonushell:mainfrom
andrasio:arguments
Feb 7, 2021
Merged

Soft rest arguments column path cohersions.#3016
andrasio merged 1 commit intonushell:mainfrom
andrasio:arguments

Conversation

@andrasio
Copy link
Copy Markdown
Member

@andrasio andrasio commented Feb 7, 2021

Closes #2979 , #2985 and probably few more I can't find in issues logged.

A couple of things. arguments helper is applied in more places (get and select, to be exact, by changing their signature type to accept a SyntaxShape::Any rather than SyntaxShape::ColumnPath which allows passing it any value type that can be converted on runtime to a column path allowing things like invocations in the arguments. Originally extracted out from empty? command.

This allows to convert the values passed to column path types and optionally determine if a block is passed at the end. This pattern (like empty?) is commonly showing up where you need to pass in columns to a command and you are interested also in having the command do a different behavior if also a block is passed to it.

With this is place, here are two examples. Given the following source file having (at the time of this writing, 41 columns). The second command we just get the last 5 column names for demonstration purposes. This file also changes everyday (more columns).

> fetch "https://raw.githubusercontent.com/andrab/ecuacovid/master/datos_crudos/defunciones/por_fecha/provincias_por_dia.csv" | get | count
41

> fetch "https://raw.githubusercontent.com/andrab/ecuacovid/master/datos_crudos/defunciones/por_fecha/provincias_por_dia.csv" | get | last 5
───┬────────────
 0 │ 02/02/2021
 1 │ 03/02/2021
 2 │ 04/02/2021
 3 │ 05/02/2021
 4 │ 06/02/2021
───┴────────────

Say we are interested in selecting just the provincia column and some random columns from January, we can do, like so:

> fetch "https://raw.githubusercontent.com/andrab/ecuacovid/master/datos_crudos/defunciones/2020/por_fecha/lugar_provincias_por_dia.csv" | select provincia $(echo 1..5 | each { = `0{{$(random integer 1..10)}}/01/2021` }) | shuffle | first 5

───┬───────────┬────────────┬────────────┬────────────┬────────────┬────────────
 # │ provincia │ 09/01/2021 │ 03/01/2021 │ 05/01/2021 │ 06/01/2021 │ 07/01/2021
───┼───────────┼────────────┼────────────┼────────────┼────────────┼────────────
 0 │ Imbabura  │         45 │          6 │         35 │         58 │         22
 1 │ Loja      │         34 │         15 │          5 │         24 │          5
 2 │ Manabí    │         80 │          8 │         63 │         86 │        107
 3 │ Orellana  │          0 │          0 │          0 │          2 │          8
 4 │ Pichincha │        311 │         26 │        425 │        478 │        180
───┴───────────┴────────────┴────────────┴────────────┴────────────┴────────────

This means select can also take Table types (the output of the invocation in positional argument and converts them to column paths as well)

select provincia $(echo 1..5 | each { = `0{{$(random integer 1..10)}}/01/2021` })

The get command also supports it now.

@andrasio andrasio merged commit debeadb into nushell:main Feb 7, 2021
@andrasio andrasio deleted the arguments branch February 7, 2021 01:05
sholderbach added a commit to sholderbach/nushell that referenced this pull request Jul 12, 2024
Fixes nushell#13359

In an attempt to generate names for flat columns resulting from a nested
accesses nushell#3016 generated new column names on nested selection, out of
convenience, that composed the cell path as a string (including `.`) and
then simply replaced all `.` with `_`. As we permit `.` in column names
as long as you quote this surprisingly alters `select`ed columns.
sholderbach added a commit that referenced this pull request Jul 13, 2024
# Description

Fixes #13359

In an attempt to generate names for flat columns resulting from a nested
accesses #3016 generated new column names on nested selection, out of
convenience, that composed the cell path as a string (including `.`) and
then simply replaced all `.` with `_`. As we permit `.` in column names
as long as you quote this surprisingly alters `select`ed columns.


# User-Facing Changes
New columns generated by selection with nested cell paths will for now
be named with a string containing the keys separated by `.` instead of
`_`. We may want to reconsider the semantics for nested access.

# Tests + Formatting
- Alter test to breaking change on nested `select`
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.

Can't convert a 'string' to a 'column'

2 participants