tobgu/qframe

Groupby error

Closed this issue · 2 comments

Running the following example in gophernotes,

	"fmt"
	"math"
	"strings"

	"github.com/tobgu/qframe"
	"github.com/tobgu/qframe/config/groupby"
	"github.com/tobgu/qframe/config/newqf"
	"github.com/tobgu/qframe/function"
	"github.com/tobgu/qframe/types"
)
intSum := func(xx []int) int {
    result := 0
    for _, x := range xx {
        result += x
    }
    return result
}

f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 2, 3, 3}, "COL2": []string{"a", "b", "c", "a", "b"}})
f = f.GroupBy(groupby.Columns("COL2")).Aggregate(qframe.Aggregation{Fn: intSum, Column: "COL1"})
fmt.Println(f.Sort(qframe.Order{Column: "COL2"}))

Got the following error message

repl.go:10:5: invalid qualified type, expecting packagename.identifier, found: f.GroupBy(groupby.Columns("COL2")).Aggregate <*ast.SelectorExpr>

and if I take out the aggregation but and simply do a groupby, it gave me

cannot use <github.com/tobgu/qframe/config/groupby.ConfigFunc> as <github.com/tobgu/qframe/config/groupby.ConfigFunc> in argument to f.GroupBy

Not sure what's going on here

Hey @AaamberW, looking at the errors you posted my guess is that your running into a limitation of gomacro which is the library that is used by Gophernotes to interpret Go code at runtime. In theory should work, but in practice I have seen a lot of edge cases with interpreted Go. Here is a list of limitations that the gomacro authors mention.

Here are steps to reproduce the issue:

I put your code from above into a main.go file such as below:

package main

import (
        "fmt"

        "github.com/tobgu/qframe"
        "github.com/tobgu/qframe/config/groupby"
)

func main() {
        intSum := func(xx []int) int {
                result := 0
                for _, x := range xx {
                        result += x
                }
                return result
        }

        f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 2, 3, 3}, "COL2": []string{"a", "b", "c", "a", "b"}})
        f = f.GroupBy(groupby.Columns("COL2")).Aggregate(qframe.Aggregation{Fn: intSum, Column: "COL1"})
        fmt.Println(f.Sort(qframe.Order{Column: "COL2"}))
}
# Running the code normally works fine:
$ go run main.go
COL2(s) COL1(i)
------- -------
      a       4
      b       5
      c       2

Dims = 2 x 3
# But if we install gomacro and try to run it:
$ gomacro main.go
// debug: looking for package "github.com/tobgu/qframe" ...
....
main.go:20:6: invalid qualified type, expecting packagename.identifier, found: f.GroupBy(groupby.Columns("COL2")).Aggregate <*ast.SelectorExpr>

@kevinschoon Thanks for the help!! Confirming that this is a Gophernotes issue so I'll close this.