gframe

package
v0.0.18-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package gframe provides a 2D data structure.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AggCount

func AggCount(name string, field ...string) aggOptFn

AggCount returns an aggregation option that counts the field identified by name.

func AggFirst

func AggFirst(name string, field ...string) aggOptFn

AggFirst returns an aggregation option that returns the first occurrence of the group.

func AggMax

func AggMax(name string, field ...string) aggOptFn

AggMax returns an aggregation option that returns the maximum value of a field.

func AggMean

func AggMean(name string, field ...string) aggOptFn

AggMean returns an aggregation option that returns the mean value of a field.

func AggSum

func AggSum(name string, field ...string) aggOptFn

AggSum returns an aggregation option that returns the sum of a field.

func GroupBy

func GroupBy(s ...IntOrString) aggGroupFn

GroupBy returns a group function that uses the selected fields on a row to be used as the group key.

func GroupByFunc

func GroupByFunc(fn func(Row) Row) aggGroupFn

GroupByFunc wrap a function that takes a row and returns a row to be used as the group key.

func GroupByFuncE

func GroupByFuncE(fn func(v Row) (Row, error)) aggGroupFn

GroupByFuncE is a convenience function for grouping a frame by a function.

func JoinOn

func JoinOn(f1, f2 string) func(r1, r2 Row) bool

JoinOn is a convinient function to create a joinOnFunc.

func Max

func Max[T conv.Numbers](s Series) T

func Min

func Min[T conv.Numbers](s Series) T

func Reduce

func Reduce[T any](name string, fn func(T, Row) T, ffn ...func(T) any) aggOptFn

Reduce adds a reduce function to aggregator.

func Sum

func Sum[T conv.Numbers](s Series) T

Types

type Field

type Field = drow.Field

Field is a field of data

func F

func F(name string, value any) Field

F returns a new field.

type FieldExpr

type FieldExpr = drow.FieldExpr

FieldExpr for Selects,At, etc..

func FE

func FE(s ...IntOrString) FieldExpr

FF Used to fetch sub fields from a row.

type FilterFunc

type FilterFunc func(Row) bool

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

Frame contains data series.

func ErrFrame

func ErrFrame(err error) Frame

ErrFrame returns a dataframe with an error.

func From

func From(data any) Frame

From make a new dataframe from a list of series

func FromIter

func FromIter(it iterator) Frame

FromIter loads an iterator into a data frame.

func FromRows

func FromRows(rows []Row) Frame

FromRows creates a frame from a slice of rows.

func New

func New(series ...Series) Frame

New creates a new dataframe with the given series

func (Frame) AppendRows

func (f Frame) AppendRows(rows ...Row) Frame

AppendRows appends rows to the frame by mapping the row fields into the proper series

func (Frame) At

func (f Frame) At(k IntOrString, i int) Field

func (Frame) Columns

func (f Frame) Columns() []string

Columns returns the series names.

func (Frame) Concat

func (f Frame) Concat(f2 Frame) Frame

Concat concatenates 2 frames.

func (Frame) Drop

func (f Frame) Drop(names ...string) Frame

Drop returns a new dataframe without named serie

func (Frame) DropRows

func (f Frame) DropRows(indexes ...int) Frame

DropRows returns a new data frame with specific rows removed.

func (Frame) Each

func (f Frame) Each(fn func(Row) error) error

Each calls fn for each row in the dataframe.

func (Frame) EachI

func (f Frame) EachI(fn func(int, Row) error) error

EachI calls fn with each row and index in the dataframe.

func (Frame) Err

func (f Frame) Err() error

Err returns the dataframe error if any

func (Frame) Filter

func (f Frame) Filter(fn FilterFunc) Frame

Filter iterates over the dataframe if the fn returns true it will forward the row to the next dataframe

func (Frame) Group

func (f Frame) Group(grpfn aggGroupFn, opts ...aggOptFn) Frame

Group initiates a group operation on a frame.

func (Frame) GroupBy

func (f Frame) GroupBy(cols ...IntOrString) FrameGroupBy

GroupBy initiates a groupby operation.

func (Frame) GroupByFunc

func (f Frame) GroupByFunc(fn func(row Row) Row) FrameGroupBy

GroupByFunc initiates a groupby operation by accepting a function that will return a row where all fields are the key.

func (Frame) GroupByFuncE

func (f Frame) GroupByFuncE(fn func(row Row) (Row, error)) FrameGroupBy

GroupByFuncE initiates a groupby operation by accepting a function that will return a row where all fields are the key and an error if any.

func (Frame) Head

func (f Frame) Head(n ...int) Frame

Head returns the first n rows of the dataframe as a new dataframe default is 5

func (Frame) Info

func (f Frame) Info() string

func (Frame) InnerJoin

func (f Frame) InnerJoin(df Frame, fn joinOnFunc) Frame

InnerJoin performs a inner join on two dataframes.

func (Frame) Insert

func (f Frame) Insert(sers ...Series) Frame

Insert return a new dataframe with the inserted series.

func (Frame) Iter

func (f Frame) Iter() etl.Iter

Iter returns a dataframe iterator

func (Frame) LeftJoin

func (f Frame) LeftJoin(df Frame, fn joinOnFunc) Frame

LeftJoin performs a left join on two dataframes.

func (Frame) Len

func (f Frame) Len() int

Len returns the number of rows in the dataframe i.e: the biggest series in the dataframe

func (Frame) Map

func (f Frame) Map(fn func(Row) Row) Frame

Map iterates over the dataframe and applies the fn to each row

func (Frame) Order

func (f Frame) Order(lessfn func(r1, r2 Row) bool) Frame

func (Frame) OrderBy

func (f Frame) OrderBy() FrameOrderBy

func (Frame) OuterJoin

func (f Frame) OuterJoin(df Frame, fn joinOnFunc) Frame

OuterJoin performs a outer join on two dataframes.

func (Frame) Prefix

func (f Frame) Prefix(p string) Frame

Prefix prefixes all series names with p.

func (Frame) Print

func (f Frame) Print()

Print prints a markdown formated dataframe using the regular fmt.Println

func (Frame) Rename

func (f Frame) Rename(o, n string) Frame

Rename renames a series in the dataframe

func (Frame) RightJoin

func (f Frame) RightJoin(df Frame, fn joinOnFunc) Frame

RightJoin performs a right join on two dataframes.

func (Frame) Row

func (f Frame) Row(i int) Row

Row retrieves a row from the dataframe.

func (Frame) Rows

func (f Frame) Rows() []Row

Rows returns all rows of the dataframe.

func (Frame) Select

func (f Frame) Select(fields ...IntOrString) Frame

Select returns a new dataframe with the selected series

func (Frame) SeriesAt

func (f Frame) SeriesAt(n IntOrString) Series

Series returns the series identified by n of the dataframe.

func (Frame) Slice

func (f Frame) Slice(start, end int) Frame

Slice all series in the dataframe to the given range

func (Frame) String

func (f Frame) String() string

String will render a markdown compatible table into a string

func (Frame) Tail

func (f Frame) Tail(n ...int) Frame

Tail returns the last n rows of the dataframe as a new dataframe default is 5

type FrameGroupBy

type FrameGroupBy struct {
	// contains filtered or unexported fields
}

FrameGroupBy contains data to perform a groupby operation.

func (FrameGroupBy) Count

func (g FrameGroupBy) Count(field string, as ...string) FrameGroupBy

Count counts the number of occurrences of the specific field.

func (FrameGroupBy) Custom

func (g FrameGroupBy) Custom(opts ...aggOptFn) FrameGroupBy

Custom adds a custom reduce function to the groupby operation.

func (FrameGroupBy) Err

func (g FrameGroupBy) Err() error

Err returns the error of the groupby operation if any.

func (FrameGroupBy) First

func (g FrameGroupBy) First(field string, as ...string) FrameGroupBy

First returns the first value of the specific field in the group.

func (FrameGroupBy) Frame

func (g FrameGroupBy) Frame() Frame

Frame apply transformations and return new frame.

func (FrameGroupBy) Max

func (g FrameGroupBy) Max(field string, as ...string) FrameGroupBy

Max returns the biggest value in the specific field.

func (FrameGroupBy) Mean

func (g FrameGroupBy) Mean(field string, as ...string) FrameGroupBy

Mean returns the avg value of the specific field.

func (FrameGroupBy) Sum

func (g FrameGroupBy) Sum(field string, as ...string) FrameGroupBy

Sum sums the values of the specific field.

type FrameOrderBy

type FrameOrderBy struct {
	// contains filtered or unexported fields
}

func (FrameOrderBy) Asc

func (f FrameOrderBy) Asc(fields ...IntOrString) FrameOrderBy

func (FrameOrderBy) Desc

func (f FrameOrderBy) Desc(fields ...IntOrString) FrameOrderBy

func (FrameOrderBy) Frame

func (f FrameOrderBy) Frame() Frame

Farme apply order and return new frame

type IntOrString

type IntOrString = drow.IntOrString

IntOrString stub interface

type IterFrame

type IterFrame struct {
	// contains filtered or unexported fields
}

IterFrame creates a frame iterator that will return Row type per iteration

func (*IterFrame) Close

func (it *IterFrame) Close() error

func (*IterFrame) Next

func (it *IterFrame) Next(context.Context) (any, error)

Next loads and returns true if there is a next value, false otherwise.

type Row

type Row = drow.Row

Row is a row of data

type Series

type Series struct {
	// contains filtered or unexported fields
}

Series is a series of data.

func S

func S[T any](name string, data ...T) Series

S creates a typed series

func SF

func SF[T any](name string, sz int, fn func(int) T) Series

SF Create a series based on func data

func SP

func SP(name string, provider SeriesProvider) Series

SP returns a series based on provider.

func (Series) Append

func (s Series) Append(data ...any) Series

Append return a new series with new data.

func (Series) AsFloat32

func (s Series) AsFloat32() []float32

AsFloat32 converts the series to a float32 slice, if the value can't be converted it will be set as the zero value.

func (Series) AsFloat64

func (s Series) AsFloat64() []float64

AsFloat64 converts the series to a float64 slice, if the value can't be converted it will be set as the zero value.

func (Series) AsInt

func (s Series) AsInt() []int

AsInt converts the series to a int slice, if the value can't be converted it will be set as the zero value.

func (Series) AsInt32

func (s Series) AsInt32() []int32

AsInt32 converts the series to a int32 slice, if the value can't be converted it will be set as the zero value.

func (Series) AsInt64

func (s Series) AsInt64() []int64

AsInt64 converts the series to a int64 slice, if the value can't be converted it will be set as the zero value.

func (Series) AsString

func (s Series) AsString() []string

AsString converts the series to a string slice, if the value can't be converted it will be set as an empty string.

func (Series) At

func (s Series) At(i int) any

At returns the element at index i or nil if i is out of bounds

func (Series) Clone

func (s Series) Clone() Series

Clone returns a based series.

func (Series) Data

func (s Series) Data() any

Data returns the underlying data slice

func (Series) Float32

func (s Series) Float32(i int) float32

func (Series) Float64

func (s Series) Float64(i int) float64

func (Series) GoString

func (s Series) GoString() string

func (Series) Int

func (s Series) Int(i int) int

func (Series) Int32

func (s Series) Int32(i int) int32

func (Series) Int64

func (s Series) Int64(i int) int64

func (Series) Len

func (s Series) Len() int

Len returns the number of elements in the series

func (Series) MergeAt

func (s Series) MergeAt(i int, s2 Series) Series

MergeAt returns a new series with the values from s2 merged into s at index i

func (Series) Name

func (s Series) Name() string

Name returns the series name

func (Series) Remove

func (s Series) Remove(indexes ...int) Series

Remove removes one or more indexes from the series.

func (Series) Size

func (s Series) Size() int

func (Series) Slice

func (s Series) Slice(start, sz int) Series

Slice a series based on start and size.

func (Series) String

func (s Series) String(i int) string

func (Series) WithName

func (s Series) WithName(name string) Series

WithName returns a cloned series with the new name.

func (Series) WithValues

func (s Series) WithValues(i int, data ...any) Series

WithValues returns a new series with the new values at index i.

type SeriesData

type SeriesData[T any] struct {
	// contains filtered or unexported fields
}

SeriesData handles underlying data of a series.

func (SeriesData[T]) At

func (s SeriesData[T]) At(i int) any

Get returns the value at index i.

func (SeriesData[T]) Clone

func (s SeriesData[T]) Clone() SeriesProvider

Clone returns a copy of the series data

func (SeriesData[T]) Data

func (s SeriesData[T]) Data() any

Data returns the series data which can be casted to .([]T)

func (SeriesData[T]) Len

func (s SeriesData[T]) Len() int

Len returns the series length

func (SeriesData[T]) Remove

func (s SeriesData[T]) Remove(indexes ...int) SeriesProvider

Remove one or more indexes from the series

func (SeriesData[T]) Size

func (s SeriesData[T]) Size() int

func (SeriesData[T]) Slice

func (s SeriesData[T]) Slice(start, sz int) SeriesProvider

Slice flattens the series and take a subset

func (SeriesData[T]) String

func (s SeriesData[T]) String() string

func (SeriesData[T]) WithValues

func (s SeriesData[T]) WithValues(off int, vs ...any) SeriesProvider

WithValues returns a copy of the series with the values set on the give index.

type SeriesProvider

type SeriesProvider interface {
	Len() int
	Data() any
	At(int) any
	// New data mem size?
	Size() int

	Clone() SeriesProvider
	WithValues(off int, data ...any) SeriesProvider
	Remove(indexes ...int) SeriesProvider
	Slice(start, sz int) SeriesProvider
}

SeriesProvider is an interface for the underlying data on the series.

Jump to

Keyboard shortcuts

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