data

package
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package data provides the in-memory columnar table model shared by every part of the application: file readers, the SQL engine, database backends and the UI all speak *data.Frame.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EstimatedSize

func EstimatedSize(f *Frame) int64

EstimatedSize returns a rough in-memory footprint of the frame in bytes: strings count as len+16 (bytes plus header), time.Time values as 24, and every other cell (int64, float64, bool, null) as 16.

func FormatValue

func FormatValue(v any) string

FormatValue renders a cell value for display.

func NullCount

func NullCount(c *Column) int

NullCount returns how many cells in the column are null (nil).

func SearchExact

func SearchExact(f *Frame, needle string) []int

SearchExact returns the indices of rows where at least one cell's display string contains needle (case-sensitive). An empty needle matches every row.

func SearchExactCols

func SearchExactCols(f *Frame, cols []int, needle string) []int

SearchExactCols returns the indices of rows where at least one of the given column cells contains needle (case-insensitive). Use this when you want to restrict search to a known subset of columns (e.g. only the visible ones).

func SearchFuzzy

func SearchFuzzy(f *Frame, needle string) []int

SearchFuzzy returns the indices of rows whose joined display string fuzzily matches needle, in frame order. An empty needle matches every row.

func Shape

func Shape(f *Frame) (rows, cols int)

Shape returns the frame's dimensions as (rows, cols).

Types

type Column

type Column struct {
	Name  string
	Type  DType
	Cells []any
}

Cell values are one of: nil (null), string, int64, float64, bool, time.Time. Readers must normalize to exactly these representations.

type DType

type DType uint8

DType identifies the logical type of a column.

const (
	TypeString DType = iota
	TypeInt
	TypeFloat
	TypeBool
	TypeDate
	TypeDatetime
)

func (DType) String

func (t DType) String() string

type Frame

type Frame struct {
	Columns []Column
}

Frame is an immutable-by-convention table. Operations that transform a frame (filter, sort, query, cast) produce a new Frame.

func Concat

func Concat(frames ...*Frame) (*Frame, error)

Concat vertically concatenates frames. The result's columns are the union of the input column names in first-seen order; rows from frames lacking a column get null cells there. When the same column name carries different types across frames, the unified column becomes TypeString and every non-null value is rendered with FormatValue.

func InferFrame

func InferFrame(f *Frame, mode string, types []string) *Frame

InferFrame converts string-typed columns produced by text readers to concrete types. It never mutates f; a new frame is returned (unconverted columns share their cell slices with f).

mode is one of:

"no"    return f unchanged.
"fast"  decide each column's type by sampling its first 128 rows, then
        convert every row. Values outside the sample that fail to parse
        become null: converting with null-on-failure keeps the column
        homogeneous, at the cost of dropping the odd unparsable cell.
"safe"  scan all rows; a column is converted only when every non-empty
        cell parses as the candidate type.

types selects which candidate types are considered: any subset of "int", "float", "boolean", "date", "datetime", or ["all"] for all five. An empty list defaults to int+float.

Empty-string cells (after trimming ASCII space) count as null candidates: they never veto a conversion and become nil in converted columns. Columns containing non-string, non-nil cells are left untouched.

func New

func New(names ...string) *Frame

New creates an empty frame with the given column names, all string-typed.

func (*Frame) AppendRow

func (f *Frame) AppendRow(vals []any)

AppendRow appends one row; vals must have NumCols entries.

func (*Frame) Cell

func (f *Frame) Cell(row, col int) any

Cell returns the raw value at (row, col); nil means null.

func (*Frame) CellString

func (f *Frame) CellString(row, col int) string

CellString renders the value at (row, col) for display.

func (*Frame) ColumnIndex

func (f *Frame) ColumnIndex(name string) int

ColumnIndex returns the index of the named column, or -1.

func (*Frame) ColumnNames

func (f *Frame) ColumnNames() []string

func (*Frame) NumCols

func (f *Frame) NumCols() int

func (*Frame) NumRows

func (f *Frame) NumRows() int

func (*Frame) Row

func (f *Frame) Row(row int) []any

Row returns the raw values of one row.

func (*Frame) Select

func (f *Frame) Select(rows []int) *Frame

Select returns a new frame containing the given rows (in order).

func (*Frame) WithCell

func (f *Frame) WithCell(row, col int, val any) *Frame

WithCell returns a copy of f with the cell at (row, col) replaced by val. The column type is preserved.

func (*Frame) WithoutRows

func (f *Frame) WithoutRows(rows []int) *Frame

WithoutRows returns a copy of f with the rows at the given indices removed. Indices are 0-based; out-of-range indices are ignored. Row order of the surviving rows is preserved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL