Skip to content
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

mut with tables and indexes seems a little off? #7381

Open
fdncred opened this issue Dec 7, 2022 · 8 comments
Open

mut with tables and indexes seems a little off? #7381

fdncred opened this issue Dec 7, 2022 · 8 comments
Labels
🐛 bug Something isn't working semantics Places where we should define/clarify nushell's semantics

Comments

@fdncred
Copy link
Collaborator

fdncred commented Dec 7, 2022

Describe the bug

how is mut supposed to work here? This seems off to me.

> mut t = [[a b]; [1 2]]
> $t.b = 5
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 5 │
╰───┴───┴───╯

while this works to update column b index 0 to 5, it seems like it should be $t.b.0 = 5 but that gives

Error: nu::shell::assignment_requires_mutable_variable (link)

  × Assignment to an immutable variable.
   ╭─[entry #41:1:1]
 1 │ $t.b.0 = 5
   · ───┬──
   ·    ╰── needs to be a mutable variable
   ╰────

i get the same error with $t.0.b = 5

It gets a little worse when you table has more than one row.

> mut t = [[a b]; [1 2] [3 4]]
> $t
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 2 │
│ 1 │ 3 │ 4 │
╰───┴───┴───╯
> $t.b = 5
> $t
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 5 │
│ 1 │ 3 │ 5 │
╰───┴───┴───╯

I could acutally live with this one because it seems like the intent is to assign 5 to all of column b.

How to reproduce

see above

Expected behavior

$t.b.0 = 5 to work

Screenshots

No response

Configuration

key value
version 0.72.2
branch main
commit_hash 017a13f
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.65.0 (897e37553 2022-11-02)
rust_channel 1.65.0-x86_64-pc-windows-msvc
cargo_version cargo 1.65.0 (4bc8f24d3 2022-10-20)
pkg_version 0.72.2
build_time 2022-12-05 14:24:44 -06:00
build_rust_channel release
features database, dataframe, default, trash, which, zip
installed_plugins custom-value generate, custom-value generate2, custom-value update, from parquet, gstat, inc, nu-example-1, nu-example-2, nu-example-3, periodic-table, pnet, query, query json, query web, query xml

Additional context

No response

@kubouch
Copy link
Contributor

kubouch commented Dec 7, 2022

Could it be related to this PR? #7318

@fdncred
Copy link
Collaborator Author

fdncred commented Dec 7, 2022

Could it be related to this PR? #7318

maybe? @webbedspace what do you think?

@sophiajt
Copy link
Member

sophiajt commented Dec 7, 2022

btw, this is also true for upsert:

> [[a b]; [1 2] [3 4]] | upsert b 5
╭───┬───┬───╮
│ # │ a │ b │
├───┼───┼───┤
│ 0 │ 1 │ 5 │
│ 1 │ 3 │ 5 │
╰───┴───┴───╯

@sophiajt
Copy link
Member

sophiajt commented Dec 7, 2022

@fdncred - interesting: $t.0.b = 5 works but $t.b.0 = 5 doesn't

@webbedspace
Copy link
Contributor

webbedspace commented Dec 8, 2022

maybe? @webbedspace what do you think?

Both this and upsert just rely on Value.upsert_data_at_cell_path(), so it should be an easy fix to tweak that.

@fdncred
Copy link
Collaborator Author

fdncred commented Dec 8, 2022

Both this and upsert just rely on Value.upsert_data_at_cell_path(), so it should be an easy fix to tweak that.

Thanks for the feedback @webbedspace. Would you be willing to try and fix this behavior?

@webbedspace
Copy link
Contributor

I'll do it… after #7309.

@sholderbach sholderbach added the semantics Places where we should define/clarify nushell's semantics label Dec 30, 2022
@fdncred fdncred added the 🐛 bug Something isn't working label Sep 26, 2023
@fdncred
Copy link
Collaborator Author

fdncred commented Sep 26, 2023

On 0.85.1, I'm still getting this $t.0.b = 5 works but $t.b.0 = 5 doesn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working semantics Places where we should define/clarify nushell's semantics
Projects
None yet
Development

No branches or pull requests

5 participants