-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolumn.go
38 lines (31 loc) · 977 Bytes
/
column.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
package bridge
import (
"errors"
"github.com/DataDog/go-python3"
"github.com/apache/arrow/go/arrow"
"github.com/apache/arrow/go/arrow/array"
)
// PyColumnToColumnWithField turns a PyColumn into a GoColumn
func PyColumnToColumnWithField(pyColumn *python3.PyObject, field arrow.Field) (*array.Column, error) {
chunks, err := PyColumnToChunkedWithField(pyColumn, field)
if err != nil {
return nil, err
}
col := array.NewColumn(field, chunks)
return col, nil
}
func PyColumnToChunkedWithField(pyColumn *python3.PyObject, field arrow.Field) (*array.Chunked, error) {
pyChunked, err := PyColumnGetPyChunked(pyColumn)
if err != nil {
return nil, err
}
defer pyChunked.DecRef()
return PyChunkedToChunked(pyChunked, field.Type)
}
func PyColumnGetPyChunked(pyColumn *python3.PyObject) (*python3.PyObject, error) {
pyChunked := pyColumn.GetAttrString("data")
if pyChunked == nil {
return nil, errors.New("could not get pyChunked")
}
return pyChunked, nil
}