Make `$record | math FUNC` recurse consistently into `$record`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 40.5k
- Forks
- 2.3k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 85
Description
Basics
- I have done a basic search through the issue tracker to find similar or related issues.
- I have made myself familiar with the available features of Nushell for the particular area this enhancement request touches.
Related problem
The math functions recurse inconsistently into stacked data structures.
For example the "scalar input" functions math abs, math ceil, math floor recurses into lists inside records:
> {alice: -1.1, bob: [1,-2,3]} | math abs | to nuon
{alice: 1.1, bob [1, 2, 3]}
but not into records inside records:
> {alice: {clair: -1.1}, bob: [1,-2,3]} | math abs
Error: nu::shell::only_supports_this_input_type
× Input type not supported.
╭─[repl_entry #1:1:10]
1 │ {alice: {clair: -1.1}, bob: [1,-2,3]} | math abs
· ──────┬────── ────┬───
· │ ╰── only int, float, filesize, or duration input data is supported
· ╰── input type: record<clair: int>
╰────
This is inconsistent.
Similar
> { alice: {claire: [1 2]}, bob: [1.1, 2.1]} | math avg alice
ERROR
but
> { alice: ({claire: [1 2]} | math avg), bob: [1.1, 2.1]}
SUCCESS
which is contrary to what I as a user would expect how | math FUNC behaves.
Describe the solution you'd like
Make
{ alice: foo, bob: bar } | math FUNC
equivalent to
{ alice: (foo | math FUNC), bob (bar | math FUNC) }
(and similarily if a cell path is given), i.e. the application of | math FUNC recurses into the record structure. This would then allow
{ alice: {claire: [1 2]}, bob: [1.1, 2.1]} | math avg
to work. I guess that this is save to do for every math function (sin, exp, sum, ...)
Describe alternatives you've considered
No response
Additional context and details
This is a followup to https://github.com/nushell/nushell/issues/18749 and its solution https://github.com/nushell/nushell/pull/18754.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the math FUNC command entry point and compare the existing handling of lists, records, and cell paths with the behavior described in issues #18749 and #18754. Verify the examples with nested records and confirm that each math function recurses consistently into record fields while preserving scalar behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100