Skip to content

Make $record | math FUNC recurse consistently into $record #18767

Description

@terrahornbeck378

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 #18749 and its solution #18754.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions