Skip to content

Commit eb3a038

Browse files
committed
fix table.rowfun() bugs that broke it entirely (#155)
Fix a couple internal bugs with variable names and ouptut packaging that were breaking rowfun.
1 parent be17e67 commit eb3a038

4 files changed

Lines changed: 55 additions & 10 deletions

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Tablicious Changelog
77
* Date/time fixes
88
* Add datevec() methods for duration and calendarDuration; add multi-argout form for datetime.datevec(). ([#153](https://github.com/apjanke/octave-tablicious/issues/153))
99
* Add duration.hms() method.
10+
* Fix table.rowfun() bugs that broke it. ([#155](https://github.com/apjanke/octave-tablicious/issues/155))
1011

1112
0.4.6 (2026-02-16)
1213
------------------

inst/@table/table.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2712,6 +2712,7 @@ function prettyprint (this)
27122712
# Input handling
27132713
mustBeA (func, 'function_handle');
27142714
mustBeA (A, 'table');
2715+
this = A;
27152716
validOptions = {'InputVariables', 'GroupingVariables', 'OutputFormat', ...
27162717
'SeparateInputs', 'ExtractCellContents', 'OutputVariableNames', ...
27172718
'NumOutputs', 'ErrorHandler'};
@@ -2729,10 +2730,10 @@ function prettyprint (this)
27292730
if (isfield (opts, 'OutputFormat'))
27302731
output_format = opts.OutputFormat;
27312732
endif
2732-
validOutputFormats = {'table','uniform','cell'};
2733-
if (! ismember (outputFormat, validOutputFormats))
2733+
validOutputFormats = {'table', 'uniform', 'cell'};
2734+
if (! ismember (output_format, validOutputFormats))
27342735
error ('table.rowfun: Invalid OutputFormat: %s. Must be one of: %s', ...
2735-
outputFormat, strjoin (validOutputFormats, ', '));
2736+
output_format, strjoin (validOutputFormats, ', '));
27362737
endif
27372738
errorHandler = [];
27382739
if isfield (opts, 'ErrorHandler')
@@ -2742,7 +2743,6 @@ function prettyprint (this)
27422743
endif
27432744
errorHandler = opts.ErrorHandler;
27442745
endif
2745-
tbl = A;
27462746
n_out_args = [];
27472747
if (isfield (opts, 'NumOutputs'))
27482748
mustBeScalar (opts.NumOutputs, 'opts.NumOutputs');
@@ -2759,7 +2759,7 @@ function prettyprint (this)
27592759
endif
27602760
out_var_names = cell (1, n_out_args);
27612761
for i = 1:n_out_args
2762-
out_var_names = sprintf ("out%d", i);
2762+
out_var_names{i} = sprintf ("out%d", i);
27632763
endfor
27642764
endif
27652765
do_separate_inputs = true;
@@ -2828,15 +2828,15 @@ function prettyprint (this)
28282828
# Output packaging
28292829
switch (output_format)
28302830
case 'table'
2831-
out_vars = cellfun (@(c) cat(1, c{:}), out_bufs);
2831+
out_vars = cellfun (@(c) cat(1, c{:}), out_bufs, 'UniformOutput', false);
28322832
out = table (out_vars{:}, 'VariableNames', out_var_names);
28332833
varargout = { out };
28342834
case 'cell'
2835-
varargout = out_vars;
2835+
varargout = out_bufs;
28362836
case 'uniform'
2837-
varargout = cellfun(@(c) cat(1, c{:}), out_bufs);
2837+
varargout = cellfun (@(c) cat(1, c{:}), out_bufs, 'UniformOutput', false);
28382838
case 'timetable'
2839-
error ('timetable is not yet implemented. Sorry.');
2839+
error ('timetable is not yet implemented in Tablicious. Sorry.');
28402840
otherwise
28412841
error ('table.rowfun: Invalid OutputFormat: ''%s''', output_format);
28422842
endswitch

inst/t/t_01_table.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
# and then modified by Andrew Janke.
1111

1212
if nargin < 1 || isempty (quiet); quiet = false; endif
13-
1413
verbose = ! quiet;
1514

1615
table_classes = {@table};

inst/t/t_01a_table_manipulation.m

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Covered by the 3-clause BSD License (see LICENSES/LICENSE-MATPOWER file for details).
2+
#
3+
# Copyright (c) 1996-2022 Power Systems Engineering Research Center (PSERC)
4+
# Copyright (c) 2024, 2026 Andrew Janke
5+
6+
function t_01a_table_manipulation (quiet)
7+
# Tests for table array manipulation functionality.
8+
9+
if nargin < 1 || isempty (quiet); quiet = false; endif
10+
verbose = ! quiet;
11+
12+
t_begin (6, quiet);
13+
14+
t_01a_01_rowfun (quiet);
15+
16+
t_end;
17+
18+
endfunction
19+
20+
function t_01a_01_rowfun (quiet)
21+
# Test rowfun().
22+
#
23+
# 6 tests.
24+
25+
if nargin < 1 || isempty (quiet); quiet = false; endif
26+
verbose = ! quiet;
27+
28+
t = table((1:4)', (-4:-1)', 'VariableNames', {'A', 'B'});
29+
30+
r = rowfun(@(a,b) a+b, t, 'InputVariables', {'A', 'B'}, 'SeparateInputs', true);
31+
32+
t_ok (isa (r, 'table'));
33+
t_ok (isequal (r.Properties.VariableNames, {'out1'}));
34+
35+
r_c = rowfun(@(a,b) a+b, t, 'InputVariables', {'A', 'B'}, 'SeparateInputs', true, 'OutputFormat', 'cell');
36+
37+
t_ok (isa (r_c, 'cell'));
38+
t_ok (isequal (r_c, {-3, -1, 1, 3}'));
39+
40+
r_u = rowfun(@(a,b) a+b, t, 'InputVariables', {'A', 'B'}, 'SeparateInputs', true, 'OutputFormat', 'uniform');
41+
42+
t_ok (isa (r_u, 'double'));
43+
t_is (r_u, [-3, -1, 1, 3]');
44+
45+
endfunction

0 commit comments

Comments
 (0)