Concat datatables
(table ...*DataTable)
| 2 | |
| 3 | // Concat datatables |
| 4 | func (left *DataTable) Concat(table ...*DataTable) (*DataTable, error) { |
| 5 | out := left.EmptyCopy() |
| 6 | out.dirty = true |
| 7 | |
| 8 | tables := make([]*DataTable, 0, 1+len(table)) |
| 9 | tables = append(tables, left) |
| 10 | tables = append(tables, table...) |
| 11 | |
| 12 | for _, t := range tables { |
| 13 | if t == nil { |
| 14 | continue |
| 15 | } |
| 16 | for _, tc := range t.cols { |
| 17 | pos := out.ColumnIndex(tc.name) |
| 18 | if pos >= 0 { |
| 19 | oc := out.cols[pos] |
| 20 | if oc.IsComputed() { |
| 21 | oc.serie.Grow(out.nrows - oc.serie.Len() + tc.serie.Len()) |
| 22 | continue |
| 23 | } |
| 24 | if err := oc.serie.Concat(tc.serie); err != nil { |
| 25 | return nil, err |
| 26 | } |
| 27 | } else { |
| 28 | out.cols = append(out.cols, tc.emptyCopy()) |
| 29 | oc := out.cols[len(out.cols)-1] |
| 30 | oc.serie.Grow(out.nrows - oc.serie.Len()) |
| 31 | if oc.IsComputed() { |
| 32 | oc.serie.Grow(tc.serie.Len()) |
| 33 | continue |
| 34 | } |
| 35 | if err := oc.serie.Concat(tc.serie); err != nil { |
| 36 | return nil, err |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | out.nrows += t.nrows |
| 41 | } |
| 42 | |
| 43 | // check |
| 44 | for _, oc := range out.cols { |
| 45 | size := out.nrows - oc.serie.Len() |
| 46 | if size > 0 { |
| 47 | oc.serie.Grow(size) |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | return out, nil |
| 52 | } |
| 53 | |
| 54 | // Concat datatables |
| 55 | func Concat(tables []*DataTable) (*DataTable, error) { |
nothing calls this directly
no test coverage detected