-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
field.go
52 lines (43 loc) · 1.14 KB
/
field.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
package bridge
import (
"errors"
"github.com/DataDog/go-python3"
"github.com/apache/arrow/go/arrow"
)
// PyFieldToField given a Python field gets the Go Arrow field.
func PyFieldToField(pyField *python3.PyObject) (*arrow.Field, error) {
pyName := pyField.GetAttrString("name")
if pyName == nil {
return nil, errors.New("could not get pyName")
}
defer pyName.DecRef()
pyDtype := pyField.GetAttrString("type")
if pyDtype == nil {
return nil, errors.New("could not get pyDtype")
}
defer pyDtype.DecRef()
pyNullable := pyField.GetAttrString("nullable")
if pyNullable == nil {
return nil, errors.New("could not get pyNullable")
}
defer pyNullable.DecRef()
// TODO: Implement
// pyMetadata := CallPyFunc(pyField, "metadata")
// if pyMetadata == nil {
// return nil, errors.New("could not get pyMetadata")
// }
name := python3.PyUnicode_AsUTF8(pyName)
dtype, err := PyDataTypeToDataType(pyDtype)
if err != nil {
return nil, err
}
nullable := python3.PyBool_Check(pyNullable)
field := &arrow.Field{
Name: name,
Type: dtype,
Nullable: nullable,
// TODO: Implement
// Metadata: metadata,
}
return field, nil
}