MCPcopy Create free account
hub / github.com/cogentcore/core / InsertColumn

Method InsertColumn

tensor/table/table.go:198–210  ·  view source on GitHub ↗

InsertColumn inserts the given tensor as a column to the table at given index, returning an error and not adding if the name is not unique. Automatically adjusts the shape to fit the current number of rows.

(tsr tensor.Tensor, name string, idx int)

Source from the content-addressed store, hash-verified

196// returning an error and not adding if the name is not unique.
197// Automatically adjusts the shape to fit the current number of rows.
198func (dt *Table) InsertColumn(tsr tensor.Tensor, name string, idx int) error {
199 if _, has := dt.ColumnNameMap[name]; has {
200 err := fmt.Errorf("table.Table duplicate column name: %s", name)
201 slog.Warn(err.Error())
202 return err
203 }
204 dt.ColumnNames = slices.Insert(dt.ColumnNames, idx, name)
205 dt.UpdateColumnNameMap()
206 dt.Columns = slices.Insert(dt.Columns, idx, tsr)
207 rows := max(1, dt.Rows)
208 tsr.SetNumRows(rows)
209 return nil
210}
211
212// AddColumnOfType adds a new scalar column to the table, of given reflect type,
213// column name (which must be unique),

Callers 1

InsertColumnFunction · 0.80

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 5

UpdateColumnNameMapMethod · 0.95
ErrorfMethod · 0.65
ErrorMethod · 0.65
SetNumRowsMethod · 0.65
InsertMethod · 0.45

Tested by

no test coverage detected