apjanke / octave-tablicious

Table (relational, tabular data) implementation for GNU Octave
https://apjanke.github.io/octave-tablicious/
GNU General Public License v3.0
28 stars 11 forks source link

Have table override fieldnames() to expose variable names #118

Closed apjanke closed 5 months ago

apjanke commented 5 months ago

The variable names in a table should show up in a fieldnames(tbl) call on a table. So should Properties, plus the two dimensions, but name. But the "internal" DimensionNames, RowNames, VariableNames, and VariableValues should not, at least not directly; they should be in a Properties field.

Looks like table needs to override fieldnames for this.

>> foo = 42; bar = 'hello'; baz = 123.456;
>> tbl = table (foo, bar, baz)
tbl =
table: 1 rows x 3 variables
  VariableNames: foo, bar, baz
>> fieldnames(tbl)
ans =
{
  [1,1] = DimensionNames
  [2,1] = RowNames
  [3,1] = VariableNames
  [4,1] = VariableValues
}

>>
apjanke commented 5 months ago

Gave this a try. Seems to work okay.

apjanke commented 5 months ago

Fixed in https://github.com/apjanke/octave-tablicious/commit/0d454fedb9a247822ddbef1d8e40dccbb269bc91.