Documentation ¶
Overview ¶
Package qframe holds the main QFrame implementation and acts as an entry point to QFrame.
Index ¶
- func Doc() string
- type Aggregation
- type AndClause
- type BoolView
- type ConstBool
- type ConstFloat
- type ConstInt
- type ConstString
- type EnumView
- type Expression
- type Filter
- type FilterClause
- type FloatView
- type GroupStats
- type Grouper
- type Instruction
- type IntView
- type NotClause
- type NullClause
- type OrClause
- type Order
- type QFrame
- func (qf QFrame) Apply(instructions ...Instruction) QFrame
- func (qf QFrame) BoolView(colName string) (BoolView, error)
- func (qf QFrame) ByteSize() int
- func (qf QFrame) ColumnNames() []string
- func (qf QFrame) ColumnTypeMap() map[string]types.DataType
- func (qf QFrame) ColumnTypes() []types.DataType
- func (qf QFrame) Contains(colName string) bool
- func (qf QFrame) Copy(dstCol, srcCol string) QFrame
- func (qf QFrame) Distinct(configFns ...groupby.ConfigFunc) QFrame
- func (qf QFrame) Drop(columns ...string) QFrame
- func (qf QFrame) EnumView(colName string) (EnumView, error)
- func (qf QFrame) Equals(other QFrame) (equal bool, reason string)
- func (qf QFrame) Eval(dstCol string, expr Expression, ff ...eval.ConfigFunc) QFrame
- func (qf QFrame) Filter(clause FilterClause) QFrame
- func (qf QFrame) FilteredApply(clause FilterClause, instructions ...Instruction) QFrame
- func (qf QFrame) FloatView(colName string) (FloatView, error)
- func (qf QFrame) GroupBy(configFns ...groupby.ConfigFunc) Grouper
- func (qf QFrame) IntView(colName string) (IntView, error)
- func (qf QFrame) Len() int
- func (qf QFrame) MustBoolView(colName string) BoolView
- func (qf QFrame) MustEnumView(colName string) EnumView
- func (qf QFrame) MustFloatView(colName string) FloatView
- func (qf QFrame) MustIntView(colName string) IntView
- func (qf QFrame) MustStringView(colName string) StringView
- func (qf QFrame) Select(columns ...string) QFrame
- func (qf QFrame) Slice(start, end int) QFrame
- func (qf QFrame) Sort(orders ...Order) QFrame
- func (qf QFrame) String() string
- func (qf QFrame) StringView(colName string) (StringView, error)
- func (qf QFrame) ToCSV(writer io.Writer) error
- func (qf QFrame) ToJSON(writer io.Writer) error
- func (qf QFrame) ToSQL(tx *sql.Tx, confFuncs ...qsql.ConfigFunc) error
- type StringView
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Aggregation ¶
type Aggregation struct { // Fn is the aggregatoin function to apply. // // IMPORTANT: For pointer and reference types you must not assume that the data passed argument // to this function is valid after the function returns. If you plan to keep it around you need // to take a copy of the data. Fn types.SliceFuncOrBuiltInId // Column is the name of the column to apply the aggregation to. Column string }
Aggregation represents a function to apply to a column.
type AndClause ¶
type AndClause comboClause
AndClause represents the logical conjunction of multiple clauses.
func And ¶
func And(clauses ...FilterClause) AndClause
And returns a new AndClause that represents the conjunction of the passed filter clauses.
type BoolView ¶
BoolView provides a "view" into an bool column and can be used for access to individual elements.
type ConstBool ¶
ConstBool describes a string column with only one value. It can be used during during construction of new QFrames.
type ConstFloat ¶
ConstFloat describes a string column with only one value. It can be used during during construction of new QFrames.
type ConstInt ¶
ConstInt describes a string column with only one value. It can be used during during construction of new QFrames.
type ConstString ¶
ConstString describes a string column with only one value. It can be used during during construction of new QFrames.
type EnumView ¶
EnumView provides a "view" into an enum column and can be used for access to individual elements.
type Expression ¶
type Expression interface { // Err returns an error if the expression could not be constructed for some reason. Err() error // contains filtered or unexported methods }
Expression is an internal interface representing an expression that can be executed on a QFrame.
func Expr ¶ added in v0.2.0
func Expr(name string, args ...interface{}) Expression
Expr represents an expression with one or more arguments. The arguments may be values, columns or the result of other expressions.
If more arguments than two are passed, the expression will be evaluated by repeatedly applying the function to pairwise elements from the left. Temporary columns will be created as necessary to hold intermediate results.
Pseudo example:
["/", 18, 2, 3] is evaluated as ["/", ["/", 18, 2], 3] (= 3)
type Filter ¶
Filter is the lowest level in a filter clause. See the docs for filter.Filter for an in depth description of the fields.
type FilterClause ¶
FilterClause is an internal interface representing a filter of some kind that can be applied on a QFrame.
type FloatView ¶
FloatView provides a "view" into an float column and can be used for access to individual elements.
type GroupStats ¶
type GroupStats grouper.GroupStats
GroupStats contains internal statistics for grouping. Clients should not depend on this for any type of decision making. It is strictly "for info". The layout may change if the underlying grouping mechanisms change.
type Grouper ¶
type Grouper struct { Err error Stats GroupStats // contains filtered or unexported fields }
Grouper contains groups of rows produced by the QFrame.GroupBy function.
func (Grouper) Aggregate ¶
func (g Grouper) Aggregate(aggs ...Aggregation) QFrame
Aggregate applies the given aggregations to all row groups in the Grouper.
Time complexity O(m*n) where m = number of aggregations, n = number of rows.
type Instruction ¶
type Instruction struct { // Fn is the function to apply. // // IMPORTANT: For pointer and reference types you must not assume that the data passed argument // to this function is valid after the function returns. If you plan to keep it around you need // to take a copy of the data. Fn types.DataFuncOrBuiltInId // DstCol is the name of the column that the result of applying Fn should be stored in. DstCol string // SrcCol1 is the first column to take arguments to Fn from. // This field is optional and must only be set if Fn takes one or more arguments. SrcCol1 string // SrcCol2 is the second column to take arguments to Fn from. // This field is optional and must only be set if Fn takes two arguments. SrcCol2 string }
Instruction describes an operation that will be applied to a row in the QFrame.
type IntView ¶
IntView provides a "view" into an int column and can be used for access to individual elements.
type NotClause ¶
type NotClause struct {
// contains filtered or unexported fields
}
NotClause represents the logical inverse of of a filter clause.
func Not ¶
func Not(c FilterClause) NotClause
Not creates a new NotClause that represents the inverse of the passed filter clause.
type NullClause ¶
type NullClause struct{}
NullClause is a convenience type to simplify clients when no filtering is to be done.
func (NullClause) String ¶
func (c NullClause) String() string
Err for NullClause always returns an empty string.
type OrClause ¶
type OrClause comboClause
OrClause represents the logical disjunction of multiple clauses.
func Or ¶
func Or(clauses ...FilterClause) OrClause
Or returns a new OrClause that represents the disjunction of the passed filter clauses.
type Order ¶
type Order struct { // Column is the name of the column to sort by. Column string // Reverse specifies if sorting should be performed ascending (false, default) or descending (true) Reverse bool }
Order is used to specify how sorting should be performed.
type QFrame ¶
type QFrame struct { // Err indicates that an error has occurred while running an operation. // If Err is set it will prevent any further operations from being executed // on the QFrame. Err error // contains filtered or unexported fields }
QFrame holds a number of columns together and offers methods for filtering, group+aggregate and data manipulation.
Example (ApplyConstant) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}}) f = f.Apply(qframe.Instruction{Fn: 1.5, DstCol: "COL2"}) fmt.Println(f) // COL1(i) COL2(f) // ------- ------- // 1 1.5 // 2 1.5 // 3 1.5 // // Dims = 2 x 3 }
Output:
Example (ApplyGenerator) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { val := -1 generator := func() int { val++ return val } f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}}) f = f.Apply(qframe.Instruction{Fn: generator, DstCol: "COL2"}) fmt.Println(f) // COL1(i) COL2(i) // ------- ------- // 1 0 // 2 1 // 3 2 // // Dims = 2 x 3 }
Output:
Example (ApplyStrConcat) ¶
package main import ( "fmt" "github.com/tobgu/qframe" "github.com/tobgu/qframe/function" ) func main() { // String concatenating COL2 and COL1. f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}, "COL2": []string{"a", "b", "c"}}) f = f.Apply( qframe.Instruction{Fn: function.StrI, DstCol: "COL1", SrcCol1: "COL1"}, qframe.Instruction{Fn: function.ConcatS, DstCol: "COL3", SrcCol1: "COL1", SrcCol2: "COL2"}) fmt.Println(f.Select("COL3")) }
Output: COL3(s) ------- 1a 2b 3c Dims = 1 x 3
Example (EvalStrConcat) ¶
package main import ( "fmt" "github.com/tobgu/qframe" "github.com/tobgu/qframe/types" ) func main() { // Same example as for apply but using Eval instead. f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}, "COL2": []string{"a", "b", "c"}}) f = f.Eval("COL3", qframe.Expr("+", qframe.Expr("str", types.ColumnName("COL1")), types.ColumnName("COL2"))) fmt.Println(f.Select("COL3")) }
Output: COL3(s) ------- 1a 2b 3c Dims = 1 x 3
Example (FilterBuiltin) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}, "COL2": []string{"a", "b", "c"}}) newF := f.Filter(qframe.Filter{Column: "COL1", Comparator: ">", Arg: 1}) fmt.Println(newF) }
Output: COL1(i) COL2(s) ------- ------- 2 b 3 c Dims = 2 x 2
Example (FilterCustomFunc) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}, "COL2": []string{"a", "b", "c"}}) isOdd := func(x int) bool { return x&1 > 0 } newF := f.Filter(qframe.Filter{Column: "COL1", Comparator: isOdd}) fmt.Println(newF) }
Output: COL1(i) COL2(s) ------- ------- 1 a 3 c Dims = 2 x 2
Example (FilterWithOrClause) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}, "COL2": []string{"a", "b", "c"}}) newF := f.Filter(qframe.Or( qframe.Filter{Column: "COL1", Comparator: ">", Arg: 2}, qframe.Filter{Column: "COL2", Comparator: "=", Arg: "a"})) fmt.Println(newF) }
Output: COL1(i) COL2(s) ------- ------- 1 a 3 c Dims = 2 x 2
Example (GroupByAggregate) ¶
package main import ( "fmt" "github.com/tobgu/qframe" "github.com/tobgu/qframe/config/groupby" ) func main() { intSum := func(xx []int) int { result := 0 for _, x := range xx { result += x } return result } f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 2, 3, 3}, "COL2": []string{"a", "b", "c", "a", "b"}}) f = f.GroupBy(groupby.Columns("COL2")).Aggregate(qframe.Aggregation{Fn: intSum, Column: "COL1"}) fmt.Println(f.Sort(qframe.Order{Column: "COL2"})) }
Output: COL2(s) COL1(i) ------- ------- a 4 b 5 c 2 Dims = 2 x 3
Example (Iter) ¶
package main import ( "fmt" "github.com/tobgu/qframe" "github.com/tobgu/qframe/types" ) func main() { qf := qframe.New(map[string]interface{}{ "COL1": []string{"a", "b", "c"}, "COL2": []int{0, 1, 2}, "COL3": []string{"d", "e", "f"}, "COL4": []int{3, 4, 5}, }) named := qf.ColumnTypeMap() for _, col := range qf.ColumnNames() { if named[col] == types.Int { view := qf.MustIntView(col) for i := 0; i < view.Len(); i++ { fmt.Println(view.ItemAt(i)) } } } }
Output: 0 1 2 3 4 5
Example (SortWithEnum) ¶
package main import ( "fmt" "github.com/tobgu/qframe" "github.com/tobgu/qframe/config/newqf" ) func main() { f := qframe.New( map[string]interface{}{"COL1": []string{"abc", "def", "ghi"}, "COL2": []string{"a", "b", "c"}}, newqf.Enums(map[string][]string{"COL2": {"c", "b", "a"}})) fmt.Println(f) fmt.Println("\nSorted according to enum spec:") fmt.Println(f.Sort(qframe.Order{Column: "COL2"})) }
Output: COL1(s) COL2(e) ------- ------- abc a def b ghi c Dims = 2 x 3 Sorted according to enum spec: COL1(s) COL2(e) ------- ------- ghi c def b abc a Dims = 2 x 3
Example (View) ¶
package main import ( "fmt" "github.com/tobgu/qframe" ) func main() { f := qframe.New(map[string]interface{}{"COL1": []int{1, 2, 3}}) v, _ := f.IntView("COL1") fmt.Println(v.Slice()) }
Output: [1 2 3]
func New ¶
New creates a new QFrame with column content from data.
Time complexity O(m * n) where m = number of columns, n = number of rows.
Example ¶
package main import ( "fmt" "math" "github.com/tobgu/qframe" "github.com/tobgu/qframe/config/newqf" ) func main() { a, c := "a", "c" f := qframe.New(map[string]interface{}{ "COL1": []int{1, 2, 3}, "COL2": []float64{1.5, 2.5, math.NaN()}, "COL3": []string{"a", "b", "c"}, "COL4": []*string{&a, nil, &c}, "COL5": []bool{false, false, true}}, newqf.ColumnOrder("COL5", "COL4", "COL3", "COL2", "COL1")) fmt.Println(f) }
Output: COL5(b) COL4(s) COL3(s) COL2(f) COL1(i) ------- ------- ------- ------- ------- false a a 1.5 1 false null b 2.5 2 true c c null 3 Dims = 5 x 3
func ReadCSV ¶ added in v0.2.0
func ReadCSV(reader io.Reader, confFuncs ...csv.ConfigFunc) QFrame
ReadCSV returns a QFrame with data, in CSV format, taken from reader. Column data types are auto detected if not explicitly specified.
Time complexity O(m * n) where m = number of columns, n = number of rows.
Example ¶
package main import ( "fmt" "strings" "github.com/tobgu/qframe" ) func main() { input := `COL1,COL2 a,1.5 b,2.25 c,3.0` f := qframe.ReadCSV(strings.NewReader(input)) fmt.Println(f) }
Output: COL1(s) COL2(f) ------- ------- a 1.5 b 2.25 c 3 Dims = 2 x 3
func ReadJSON ¶ added in v0.2.0
func ReadJSON(reader io.Reader, fns ...newqf.ConfigFunc) QFrame
ReadJSON returns a QFrame with data, in JSON format, taken from reader.
Time complexity O(m * n) where m = number of columns, n = number of rows.
func ReadSQL ¶ added in v0.2.0
func ReadSQL(tx *sql.Tx, confFuncs ...qsql.ConfigFunc) QFrame
ReadSQL returns a QFrame by reading the results of a SQL query.
func (QFrame) Apply ¶
func (qf QFrame) Apply(instructions ...Instruction) QFrame
Apply applies instructions to each row in the QFrame.
Time complexity O(m * n), where m = number of instructions, n = number of rows.
func (QFrame) BoolView ¶
BoolView returns a view into an bool column identified by name.
colName - Name of the column.
Returns an error if the column is missing or of wrong type. Time complexity O(1).
func (QFrame) ByteSize ¶
ByteSize returns a best effort estimate of the current size occupied by the QFrame.
This does not factor for cases where multiple, different, frames reference the same underlying data.
Time complexity O(m) where m is the number of columns in the QFrame.
func (QFrame) ColumnNames ¶
ColumnNames returns the names of all columns in the QFrame.
Time complexity O(n) where n = number of columns.
func (QFrame) ColumnTypeMap ¶ added in v0.2.0
ColumnTypeMap returns a map of each underlying column with the column name as a key and it's types.DataType as a value.
Time complexity O(n) where n = number of columns.
func (QFrame) ColumnTypes ¶ added in v0.2.0
ColumnTypes returns all underlying column types.DataType
Time complexity O(n) where n = number of columns.
func (QFrame) Contains ¶
Contains reports if a columns with colName is present in the frame.
Time complexity is O(1).
func (QFrame) Copy ¶
Copy copies the content of dstCol into srcCol.
dstCol - Name of the column to copy to. srcCol - Name of the column to copy from.
Time complexity O(1). Under the hood no actual copy takes place. The columns will share the underlying data. Since the frame is immutable this is safe.
func (QFrame) Distinct ¶
func (qf QFrame) Distinct(configFns ...groupby.ConfigFunc) QFrame
Distinct returns a new QFrame that only contains unique rows with respect to the specified columns. If no columns are given Distinct will return rows where allow columns are unique.
The order of the returned rows in undefined.
Time complexity O(m * n) where m = number of columns to compare for distinctness, n = number of rows.
func (QFrame) Drop ¶
Drop creates a new projection of te QFrame without the specified columns.
Time complexity O(1).
func (QFrame) EnumView ¶
EnumView returns a view into an enum column identified by name.
colName - Name of the column.
Returns an error if the column is missing or of wrong type. Time complexity O(1).
func (QFrame) Equals ¶
Equals compares this QFrame to another QFrame. If the QFrames are equal (true, "") will be returned else (false, <string describing why>) will be returned.
Time complexity O(m * n) where m = number of columns to group by, n = number of rows.
func (QFrame) Eval ¶
func (qf QFrame) Eval(dstCol string, expr Expression, ff ...eval.ConfigFunc) QFrame
Eval evaluates an expression assigning the result to dstCol.
Eval can be considered an abstraction over Apply. For example it handles management of intermediate/temporary columns that are needed as part of evaluating more complex expressions.
Time complexity O(m*n) where m = number of clauses in the expression, n = number of rows.
func (QFrame) Filter ¶
func (qf QFrame) Filter(clause FilterClause) QFrame
Filter filters the frame according to the filters in clause.
Filters are applied via depth first traversal of the provided filter clause from left to right. Use the following rules of thumb for best performance when constructing filters:
- Cheap filters (eg. integer comparisons, ...) should go to the left of more expensive ones (eg. string regex, ...).
- High impact filters (eg. filters that you expect will drop a lot of data) should go to the left of low impact filters.
Time complexity O(m * n) where m = number of columns to filter by, n = number of rows.
func (QFrame) FilteredApply ¶
func (qf QFrame) FilteredApply(clause FilterClause, instructions ...Instruction) QFrame
FilteredApply works like Apply but allows adding a filter which limits the rows to which the instructions are applied to. Any rows not matching the filter will be assigned the zero value of the column type.
Time complexity O(m * n), where m = number of instructions, n = number of rows.
func (QFrame) FloatView ¶
FloatView returns a view into an float column identified by name.
colName - Name of the column.
Returns an error if the column is missing or of wrong type. Time complexity O(1).
func (QFrame) GroupBy ¶
func (qf QFrame) GroupBy(configFns ...groupby.ConfigFunc) Grouper
GroupBy groups rows together for which the values of specified columns are the same. Aggregations on the groups can be executed on the returned Grouper object. Leaving out columns to group by will make one large group over which aggregations can be done.
The order of the rows in the Grouper is undefined.
Time complexity O(m * n) where m = number of columns to group by, n = number of rows.
func (QFrame) IntView ¶
IntView returns a view into an int column identified by name.
colName - Name of the column.
Returns an error if the column is missing or of wrong type. Time complexity O(1).
func (QFrame) MustBoolView ¶ added in v0.2.0
MustBoolView returns a view into an bool column identified by name.
colName - Name of the column.
Panics if the column is missing or of wrong type. Time complexity 0(1).
func (QFrame) MustEnumView ¶ added in v0.2.0
MustEnumView returns a view into an enum column identified by name.
colName - Name of the column.
Panics if the column is missing or of wrong type. Time complexity 0(1).
func (QFrame) MustFloatView ¶ added in v0.2.0
MustFloatView returns a view into an float column identified by name.
colName - Name of the column.
Panics if the column is missing or of wrong type. Time complexity 0(1).
func (QFrame) MustIntView ¶ added in v0.2.0
MustIntView returns a view into an int column identified by name.
colName - Name of the column.
Panics if the column is missing or of wrong type. Time complexity 0(1).
func (QFrame) MustStringView ¶ added in v0.2.0
func (qf QFrame) MustStringView(colName string) StringView
MustStringView returns a view into an string column identified by name.
colName - Name of the column.
Panics if the column is missing or of wrong type. Time complexity 0(1).
func (QFrame) Select ¶
Select creates a new projection of the QFrame containing only the specified columns.
Time complexity O(1).
func (QFrame) Slice ¶
Slice returns a new QFrame consisting of rows [start, end[. Note that the underlying storage is kept. Slicing a frame will not release memory used to store the columns.
Time complexity O(1).
func (QFrame) Sort ¶
Sort returns a new QFrame sorted according to the orders specified.
Time complexity O(m * n * log(n)) where m = number of columns to sort by, n = number of rows in QFrame.
func (QFrame) String ¶
String returns a simple string representation of the table. Column type is indicated in parenthesis following the column name. The initial letter in the type name is used for this. Output is currently capped to 50 rows. Use Slice followed by String if you want to print rows that are not among the first 50.
func (QFrame) StringView ¶
func (qf QFrame) StringView(colName string) (StringView, error)
StringView returns a view into an string column identified by name.
colName - Name of the column.
Returns an error if the column is missing or of wrong type. Time complexity O(1).
func (QFrame) ToCSV ¶ added in v0.2.0
ToCSV writes the data in the QFrame, in CSV format, to writer.
Time complexity O(m * n) where m = number of rows, n = number of columns.
This is function is currently unoptimized. It could probably be a lot speedier with a custom written CSV writer that handles quoting etc. differently.
type StringView ¶
StringView provides a "view" into an string column and can be used for access to individual elements.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
Package config acts as a base package for different configuration options used when creating or working with QFrames.
|
Package config acts as a base package for different configuration options used when creating or working with QFrames. |
contrib
|
|
gonum/qplot
package qplot provides compatibility between QFrame and gonum.org/v1/plot
|
package qplot provides compatibility between QFrame and gonum.org/v1/plot |
Package function contains example functions that can be used in QFrame.Apply and QFrame.Eval.
|
Package function contains example functions that can be used in QFrame.Apply and QFrame.Eval. |
internal
|
|