From 78ebf3603985547bc3f90e7ab6001f6f74c01ed3 Mon Sep 17 00:00:00 2001 From: tonythethompson Date: Wed, 1 Jul 2026 20:42:45 -0700 Subject: [PATCH] fix(maths): scale-minmax-table fails on current Nu (undefined column2, deprecated merge) scale-minmax-table has been broken as a standalone module command since it was added: it calls `column2`, which is defined only in sourced/misc/nu_defs.nu (an unrelated personal-dotfiles file) rather than in this module. It only ever worked in a shell where that file happened to already be sourced separately. Separately, current Nu's `merge` no longer accepts the closure form `merge {$it}` used here -- `merge` now takes a `record`/`table` value directly (see `help merge`), so this also fails to parse on anything recent regardless of the column2 issue. Fixes: - Add a local `column2` helper (same implementation as sourced/misc/nu_defs.nu) so the module doesn't depend on unrelated files being sourced first. - `merge {$it}` -> `merge $it`. Verified on Nu 0.113.1: the whole module now parses, and `[[a b]; [1 10] [2 20] [3 30]] | scale-minmax-table 0 1` produces the correct per-column min-max scaling. Also spot-checked root, croot, and delta still work unchanged. --- modules/maths/math_functions.nu | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/modules/maths/math_functions.nu b/modules/maths/math_functions.nu index 26e881d33..381e43171 100644 --- a/modules/maths/math_functions.nu +++ b/modules/maths/math_functions.nu @@ -1,3 +1,9 @@ +# Get the nth column of a table as a list of values, by position rather +# than name. Used internally by `scale-minmax-table`. +def column2 [n] { + transpose | get $n | transpose | get column1 | skip 1 +} + #Root with a custom denominator export def root [ denominator, num ] { $num ** ( 1 / $denominator ) | math round -p 10 @@ -155,7 +161,7 @@ export def scale-minmax-table [a, b,input?] { 0..($n_cols - 1) | each {|i| ($x | column2 $i) | scale-minmax $a $b | wrap ($name_cols | get $i) - } | reduce {|it, acc| $acc | merge {$it}} + } | reduce {|it, acc| $acc | merge $it} }