MCPcopy Create free account
hub / github.com/datasweet/datatable / ToMap

Method ToMap

export.go:28–55  ·  view source on GitHub ↗

ToMap to export the datatable to a json-like struct

(opt ...ExportOption)

Source from the content-addressed store, hash-verified

26
27// ToMap to export the datatable to a json-like struct
28func (t *DataTable) ToMap(opt ...ExportOption) []map[string]interface{} {
29 if t == nil {
30 return nil
31 }
32
33 opts := newExportOptions(opt...)
34 if err := t.evaluateExpressions(); err != nil {
35 panic(err)
36 }
37
38 // visible columns
39 cols := make(map[string]int)
40 for i, col := range t.cols {
41 if opts.WithHiddenCols || col.IsVisible() {
42 cols[col.Name()] = i
43 }
44 }
45
46 rows := make([]map[string]interface{}, 0, t.nrows)
47 for i := 0; i < t.nrows; i++ {
48 r := make(map[string]interface{}, len(cols))
49 for name, pos := range cols {
50 r[name] = t.cols[pos].serie.Get(i)
51 }
52 rows = append(rows, r)
53 }
54 return rows
55}
56
57// ToTable to export the datatable to a csv-like struct
58func (t *DataTable) ToTable(opt ...ExportOption) [][]interface{} {

Callers 1

TestToMapFunction · 0.80

Calls 5

evaluateExpressionsMethod · 0.95
newExportOptionsFunction · 0.85
IsVisibleMethod · 0.65
NameMethod · 0.65
GetMethod · 0.65

Tested by 1

TestToMapFunction · 0.64