/
default_transformable.go
57 lines (46 loc) · 1.5 KB
/
default_transformable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package dataframe
import (
"github.com/AdikaStyle/go-df/backend"
"github.com/AdikaStyle/go-df/conds"
"github.com/AdikaStyle/go-df/types"
)
type defaultTransformable struct {
df Dataframe
}
func newDefaultTransformable(df Dataframe) *defaultTransformable {
return &defaultTransformable{df: df}
}
func (this *defaultTransformable) UpdateColumn(name string, fn backend.MutateFunction) Dataframe {
this.df.getBackend().UpdateColumn(name, fn)
return this.df
}
func (this *defaultTransformable) AddColumn(name string, kind types.TypeKind, fn backend.MutateFunction) Dataframe {
this.df.getBackend().AddColumn(name, kind, fn)
return this.df
}
func (this *defaultTransformable) Concat(with Dataframe) Dataframe {
with.VisitRows(func(id int, row backend.Row) {
this.df.getBackend().AppendRow(row)
})
return this.df
}
func (this *defaultTransformable) Split(cond conds.Condition) (onTrue Dataframe, onFalse Dataframe) {
onTrue = this.df.constructNew(this.df.GetHeaders())
onFalse = this.df.constructNew(this.df.GetHeaders())
this.df.VisitRows(func(id int, row backend.Row) {
if cond(row) {
onTrue.getBackend().AppendRow(row)
} else {
onFalse.getBackend().AppendRow(row)
}
})
return onTrue, onFalse
}
func (this *defaultTransformable) CastColumn(name string, to types.TypeKind) Dataframe {
this.df.getBackend().CastColumn(name, to)
return this.df
}
func (this *defaultTransformable) Apply(name string, fn backend.ApplyFunction) Dataframe {
this.df.getBackend().ApplyOnColumn(name, fn)
return this.df
}