Closed vlamai closed 6 years ago
Any issues with this one?
Please stop write messages like in chat or create chat in discord or gitter.
This function is just for test, how it will work. Isn't work
package main
import (
"fmt"
"github.com/kzoper/dataframe-go"
"github.com/kzoper/dataframe-go/stat"
)
func main() {
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, -23.4, 56.2, nil, nil, 84.2, 72, 89)
stat.StFloat64{SeriesFloat64: s2}.Abs()
fmt.Println(s2)
}
Github automatically makes it like chat format. I just wrote "single comments" in the "Files Changed" tab. They end up in the "conversations" section as "chat like" comments.
The main issue is in your stat
package, you are referencing "github.com/rocketlaunchr/dataframe-go"
, but in your main file, you are referencing "github.com/kzoper/dataframe-go"
so they are different types.
I also see what you are trying to do. In that case remove the pointers and pointer references:
type StFloat64 struct {
dataframe.SeriesFloat64
}
type SeriesInt64 struct {
dataframe.SeriesInt64
}
func (s StFloat64) Abs() {
for key, value := range s.Values {
if value == nil {
continue
}
val := math.Abs(*value)
s.Values[key] = &val
}
}
func (s SeriesInt64) Abs() {
for key, value := range s.Values {
val := *value
if val < 0 {
val = val * -1
}
s.Values[key] = &val
}
}
In your main.go
:
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, -23.4, 56.2, nil, nil, 84.2, 72, 89)
stat.StFloat64{*s2}.Abs()
fmt.Println(s2)
No. Change reference and :
package main
import (
"fmt"
"github.com/kzoper/dataframe-go"
"github.com/kzoper/dataframe-go/stat"
)
func main() {
//s1 := dataframe.NewSeriesInt64("day", nil, 1, 2, 3, 4, 5, 6, 7, 8)
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, -23.4, 56.2, nil, nil, 84.2, 72, 89)
//df := dataframe.NewDataFrame(s1, s2)
stat.StFloat64{SeriesFloat64: s2}.Abs() // error
fmt.Println(s2)
}
./main.go:13:35: cannot call pointer method on stat.StFloat64 literal ./main.go:13:35: cannot take the address of stat.StFloat64 literal
See my prior comment:
1) In stat package - remove pointers and pointer receivers in the your functions (sorry for misleading you. I now have a better understanding of what you are trying to do)
2) stat.StFloat64{*s2}.Abs()
// dereference the pointer
package stat
import (
"github.com/kzoper/dataframe-go"
"math"
)
type Stat interface {
dataframe.Series
Abs()
}
type StFloat64 struct {
dataframe.SeriesFloat64
}
type SeriesInt64 struct {
dataframe.SeriesInt64
}
func (s *StFloat64) Abs() {
for key, value := range s.Values {
val := math.Abs(*value)
s.Values[key] = &val
}
}
func (s *SeriesInt64) Abs() {
for key, value := range s.Values {
val := *value
if val < 0 {
val = val * -1
}
s.Values[key] = &val
}
}
// it remove pointer here isn't work too
func (s StFloat64) Abs() {
for key, value := range s.Values {
val := math.Abs(*value)
s.Values[key] = &val
}
}
change. Still isn't working
I just cloned your package and made the above changes and it works.
package stat
import (
"github.com/kzoper/dataframe-go"
"math"
)
type Stat interface {
dataframe.Series
Abs()
}
type StFloat64 struct {
dataframe.SeriesFloat64
}
type SeriesInt64 struct {
dataframe.SeriesInt64
}
func (s StFloat64) Abs() {
for key, value := range s.Values {
val := math.Abs(*value) // ERROR HERE
s.Values[key] = &val
}
}
func (s *SeriesInt64) Abs() {
for key, value := range s.Values {
val := *value
if val < 0 {
val = val * -1
}
s.Values[key] = &val
}
}
package main
import (
"fmt"
"github.com/kzoper/dataframe-go"
"github.com/kzoper/dataframe-go/stat"
)
func main() {
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, -23.4, 56.2, nil, nil, 84.2, 72, 89)
stat.StFloat64{*s2}.Abs()
fmt.Println(s2)
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4ac3d4]
goroutine 1 [running]:
github.com/kzoper/dataframe-go/stat.StFloat64.Abs(0x4e9c18, 0x0, 0x0, 0x0, 0x4e263a, 0x5, 0xc000024300, 0x8, 0x8)
/home/kzoper/go/src/github.com/kzoper/dataframe-go/stat/stat.go:23 +0x74
main.main()
/home/kzoper/go/src/github.com/kzoper/dataFramTest/main.go:11 +0x1e7
Process finished with exit code 2
You have to do a nil check because some of your values are nil. See the image I attached.
50.3, -23.4, 56.2, nil, nil, 84.2, 72, 89
The 2 nils are causing the issue.
Now it works
Why did you close the PR?
another try