GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(transpose): return an empty record for empty input with --as-record by Surri757 · Pull Request #19681 · nushell/nushell Conversation
|
|
This PR comes from a fork, so the workflows need a maintainer to approve running them - could someone click "Approve and run workflows"? The change makes |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The fix works: [] | transpose -d gives {}, and the new tests, the example tests and clippy pass. It also makes [] | transpose -dr | load-env work, the pipe that std-rfc's kv universal-variable-hook ends in. Two small things are left: the release note should call out the behavior change, and the round-trip test should use -r -d.
Findings: 0
Notes from my clanker, checked on 24472c0. Built the branch and ran cargo test -p nu-command --test tests -- commands::transpose (14 passed), cargo test -p nu-command --lib transpose (2 passed), clippy with CI's flags (clean), cargo fmt --all --check and typos (clean). CI passed on this head too. Each case in the threads ran on the branch binary and on 0.117.1 (dc352ef).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| }) | ||
| .collect::<Vec<Value>>(); | ||
| if result_data.len() == 1 && args.as_record { | ||
| if args.as_record && result_data.len() <= 1 { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
On 24472c0, any transpose -d whose result has no rows returns {} instead of []. Commands downstream that expected a list now act differently:
[] | transpose -d | length # main: 0 # branch: Error: nu::shell::only_supports_this_input_type (input type: record) [] | transpose -d | each {|r| 'ran' } | to nuon # main: [] # branch: "ran" [] | transpose -d | append 1 | to nuon # main: [1] # branch: [{}, 1]
Input with rows can end up here too, whenever no column is left to turn into a row:
[{}] | transpose -d | to nuon # main: [] branch: {}
[[key]; [a] [b]] | transpose -r -d | to nuon # main: [] branch: {}The code doesn't need to change for this. The release note should say that scripts which treat an empty transpose -d result as a list will break.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@C:\Users\38235.minimax\bunny\spaces\GitHub-PR-反馈修改-2df9c5b7-dd63-4cc5-825c-7a6a607f837c\artifacts\f231d7a9-nushell-19681-维护者评审意见处理\reply-1-release-note.txt
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // --as-record is the inverse of transpose for records, so the | ||
| // round trip of an empty record has to stay an empty record. | ||
| test() | ||
| .run("{} | transpose | transpose --as-record | to nuon") | ||
| .expect_value_eq("{}") |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
-r
The comment says --as-record is the inverse of transpose. On its own it isn't, so this test pins a round trip that only holds for {}:
{a: 1} | transpose | transpose --as-record | to nuon
# [["column0", "column1"]; ["column0", a], ["column1", 1]]
{a: 1} | transpose | transpose -r -d | to nuon
# {a: 1}The inverse needs -r, as in the issue's ($record | transpose | transpose -rd) == $record and the transpose --ignore-titles -r -d example. Testing that form also covers the --header-row path with empty input, and it gives {} on the branch:
| // --as-record is the inverse of transpose for records, so the | |
| // round trip of an empty record has to stay an empty record. | |
| test() | |
| .run("{} | transpose | transpose --as-record | to nuon") | |
| .expect_value_eq("{}") | |
| // `transpose -r -d` is the inverse of `transpose` for records, so the | |
| // round trip of an empty record has to stay an empty record. | |
| test() | |
| .run("{} | transpose | transpose -r -d | to nuon") | |
| .expect_value_eq("{}") |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
transpose --as-record returns empty list when input is empty list
There was an error while loading. Please reload this page.