Skip to content

Commit

Permalink
PS 2
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Jan 14, 2019
1 parent 386337b commit b25ef51
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
2 changes: 1 addition & 1 deletion dframe/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Using Arrow should also allow seamless interoperability with other data wranglin
Operations on a `QFrame`, such as copying columns, dropping columns, sorting them or applying some kind of operation on columns, return a new `QFrame`, leaving the original untouched.

Arrow uses a ref-counting mechanism for all the types that involve memory allocation (mainly to address workloads involving memory allocated on a GPGPU, by a SQL database or a mmap-file.)
This ref-counting mechanism is presented to the user as a pair of methods `Retain/Release` that resp. increment and decrement that reference count.
This ref-counting mechanism is presented to the user as a pair of methods `Retain`/`Release` that increment and decrement that reference count.
At first, it would seem this mechanism would prevent to expose an API with "chained methods", as the intermediate `Frame` would be "leaked":

```go
Expand Down
10 changes: 6 additions & 4 deletions dframe/dfmat/dfmat.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,20 @@ func newConfig(n int) *config {
func FromMatrix(m mat.Matrix, opts ...Option) *dframe.Frame {
var (
mem = memory.NewGoAllocator()
bld = array.NewFloat64Builder(mem)

r, c = m.Dims()
arrs = make([]array.Interface, c)
fields = make([]arrow.Field, c)
)
defer bld.Release()

cfg := newConfig(c)
for _, opt := range opts {
opt(cfg)
}

bld := array.NewFloat64Builder(mem)
defer bld.Release()

switch m := m.(type) {
case mat.RawColViewer:
for i := 0; i < c; i++ {
Expand Down Expand Up @@ -99,19 +100,20 @@ func FromMatrix(m mat.Matrix, opts ...Option) *dframe.Frame {
func FromVector(vec mat.Vector, opts ...Option) *dframe.Frame {
var (
mem = memory.NewGoAllocator()
bld = array.NewFloat64Builder(mem)

rows = vec.Len()
arrs = make([]array.Interface, 1)
fields = make([]arrow.Field, 1)
)
defer bld.Release()

cfg := newConfig(1)
for _, opt := range opts {
opt(cfg)
}

bld := array.NewFloat64Builder(mem)
defer bld.Release()

switch vec := vec.(type) {
case mat.RawColViewer:
col := vec.RawColView(0)
Expand Down
18 changes: 7 additions & 11 deletions dframe/dframe.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ type Frame struct {
rows int64
}

var _ array.Table = (*Frame)(nil)

// Dict is a map of string to array of data.
type Dict map[string]interface{}

Expand Down Expand Up @@ -271,14 +273,12 @@ func FromCols(cols []array.Column, opts ...Option) (*Frame, error) {
}
}

{
fields := make([]arrow.Field, len(cols))
for i, col := range cols {
fields[i].Name = col.Name()
fields[i].Type = col.DataType()
}
df.schema = arrow.NewSchema(fields, nil)
fields := make([]arrow.Field, len(cols))
for i, col := range cols {
fields[i].Name = col.Name()
fields[i].Type = col.DataType()
}
df.schema = arrow.NewSchema(fields, nil)

// validate the data frame and its constituents.
// note we retain the columns after having validated the data frame
Expand Down Expand Up @@ -622,7 +622,3 @@ func (tx *Tx) Drop(cols ...string) *Tx {
tx.df.schema = sc
return tx
}

var (
_ array.Table = (*Frame)(nil)
)
4 changes: 0 additions & 4 deletions dframe/dframe_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
)

func ExampleFrame_fromTable() {

pool := memory.NewGoAllocator()

schema := arrow.NewSchema(
Expand Down Expand Up @@ -90,7 +89,6 @@ func ExampleFrame_fromTable() {
}

func ExampleFrame_fromArrays() {

pool := memory.NewGoAllocator()

schema := arrow.NewSchema(
Expand Down Expand Up @@ -149,7 +147,6 @@ func ExampleFrame_fromArrays() {
}

func ExampleFrame_fromCols() {

pool := memory.NewGoAllocator()

schema := arrow.NewSchema(
Expand Down Expand Up @@ -220,7 +217,6 @@ func ExampleFrame_fromCols() {
}

func ExampleFrame_fromFrame() {

pool := memory.NewGoAllocator()

schema := arrow.NewSchema(
Expand Down

0 comments on commit b25ef51

Please sign in to comment.