I'm working on code to integrate Google Sheets with a dataframe sdk: https://github.com/kniren/gota. This code causes a panic at "df := dataframe.LoadRecords(values)" everytime. When I use a debugger it shows a panic. Everything in the watcher shows values in my [][]string exactly as expected. If there is a better way to convert sheets cells into an [][]string, please comment.
package main
import (
"bitbucket.org/gosheets"
"fmt"
"github.com/kniren/gota/dataframe"
"reflect"
)
func main() {
sheetdata := gosheets.Setup()
// row1 is column names
fmt.Println(reflect.TypeOf(sheetdata.Values))
values := [][]string{}
//sheetdata.Values.(*sheets.ValueRange)
fmt.Sprintln(sheetdata.Values)
for _, row := range sheetdata.Values.Values {
sr := []string{}
for i, cell := range row {
//capping columns at 5 for starters
if i >= 5 {
break
}
sr = append(sr, fmt.Sprint(cell))
}
fmt.Sprintln(row)
values = append(values, sr)
//values = append(values, fmt.Sprintln(row))
}
//opts := dataframe.LoadOption{detectTypes: false}
df := dataframe.LoadRecords(values)
//df := dataframe.ReadCSV(sheetdata.Values)
//fmt.Println(sheetdata.Values)
fmt.Println(df.Names())
}
Try to provide a runnable example, as it makes it easier to debug. This looks like it uses private code, but you should be able to reproduce without using your gosheets lib, with test input.
So trying this for example as sheetdata produces a panic:
sheetdata := [][]string{{"1", "2", "3", "4", "5"}, {"1", "2", "3"}}
https://play.golang.org/p/hJXBlO_40O
so if your error is this:
panic: runtime error: index out of range
github.com/kniren/gota/dataframe.LoadRecords(0xc420058060, 0x2, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
github.com/kniren/gota/dataframe/dataframe.go:693 +0xc53
Your probably have data which has header fields longer than following rows (assuming it is looking at csv data). This assumption is baked in here, LoadRecords should really check and return an error not panic.