Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

fix: write binary table keeping data #60

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion column.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,15 @@ func (col *Column) writeBin(table *Table, icol int, irow int64, ptr interface{})
}

case reflect.Array:
rvPtr := reflect.New(rv.Type()).Elem()
rvPtr.Set(rv)

beg := table.rowsz*int(irow) + col.offset
end := beg + (col.dtype.dsize * col.dtype.len)

w := newWriter(table.data[beg:end])
switch slice := rv.Slice(0, rv.Len()).Interface().(type) {

switch slice := rvPtr.Slice(0, rv.Len()).Interface().(type) {
case []bool:
w.writeBools(slice)

Expand Down
4 changes: 1 addition & 3 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,12 +412,10 @@ func (t *Table) writeMap(data map[string]interface{}) error {

for _, icol := range icols {
col := t.Col(icol)
val := reflect.New(col.Type())
err = col.write(t, icol, t.nrows, val.Interface())
err = col.write(t, icol, t.nrows, data[col.Name])
if err != nil {
return err
}
data[col.Name] = val.Elem().Interface()
}
return err
}
Expand Down
16 changes: 12 additions & 4 deletions table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2046,6 +2046,10 @@ func TestTableMapsRW(t *testing.T) {
},
{
Name: "E",
Format: "10A",
},
{
Name: "F",
Format: "2D",
},
},
Expand All @@ -2056,28 +2060,32 @@ func TestTableMapsRW(t *testing.T) {
"B": float64(10),
"C": []int64{10, 10},
"D": []float64{10, 10},
"E": [2]float64{10, 10},
"E": string("10"),
"F": [2]float64{10, 10},
},
{
"A": int64(11),
"B": float64(11),
"C": []int64{11, 11},
"D": []float64{11, 11},
"E": [2]float64{11, 11},
"E": string("11"),
"F": [2]float64{11, 11},
},
{
"A": int64(12),
"B": float64(12),
"C": []int64{12, 12},
"D": []float64{12, 12},
"E": [2]float64{12, 12},
"E": string("12"),
"F": [2]float64{12, 12},
},
{
"A": int64(13),
"B": float64(13),
"C": []int64{13, 13},
"D": []float64{13, 13},
"E": [2]float64{13, 13},
"E": string("13"),
"F": [2]float64{13, 13},
},
},
},
Expand Down