series

package
v0.12.2 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const NaN = "NaN"

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v0.12.0

type Cache interface {
	Set(key string, value interface{})
	Get(key string) (interface{}, bool)
	Clear()
	Size() int
	Delete(key string)
	Copy() Cache
	State() string
}

Cache define series cache

type Comparator

type Comparator string

Comparator is a convenience alias that can be used for a more type safe way of reason and use comparators.

const (
	Eq        Comparator = "=="   // Equal
	Neq       Comparator = "!="   // Non equal
	Greater   Comparator = ">"    // Greater than
	GreaterEq Comparator = ">="   // Greater or equal than
	Less      Comparator = "<"    // Lesser than
	LessEq    Comparator = "<="   // Lesser or equal than
	In        Comparator = "in"   // Inside
	CompFunc  Comparator = "func" // user-defined comparison function
)

Supported Comparators

type Element added in v0.8.0

type Element interface {
	// Setter method
	Set(interface{})
	SetElement(val Element)
	SetBool(val bool)
	SetFloat(val float64)
	SetInt(val int)
	SetString(val string)

	// Comparation methods
	Eq(Element) bool
	Neq(Element) bool
	Less(Element) bool
	LessEq(Element) bool
	Greater(Element) bool
	GreaterEq(Element) bool

	// Accessor/conversion methods
	Copy() Element     // FIXME: Returning interface is a recipe for pain
	Val() ElementValue // FIXME: Returning interface is a recipe for pain
	String() string
	Int() (int, error)
	Float() float64
	Bool() (bool, error)

	// Information methods
	IsNA() bool
	Type() Type
}

Element is the interface that defines the types of methods to be present for elements of a Series

type ElementValue added in v0.8.0

type ElementValue interface{}

ElementValue represents the value that can be used for marshaling or unmarshaling Elements.

type Elements added in v0.9.0

type Elements interface {
	Elem(int) Element
	Len() int
	Slice(start, end int) Elements
	Get(indexs ...int) Elements
	Append(Elements) Elements
	AppendOne(Element) Elements
	Copy() Elements
}

Elements is the interface that represents the array of elements contained on a Series.

type FilterFunction added in v0.12.1

type FilterFunction func(ele Element, index int) bool

FilterFunction Select the elements that match the FilterFunction

type FloatValuer added in v0.12.2

type FloatValuer interface {
	// Float returns a float64 value.
	Float() float64
}

FloatValuer is the interface providing the Float method.

Types implementing FloatValuer interface are able to convert themselves to a float Value.

type Indexes

type Indexes interface{}

Indexes represent the elements that can be used for selecting a subset of elements within a Series. Currently supported are:

int            // Matches the given index number
[]int          // Matches all given index numbers
[]bool         // Matches all elements in a Series marked as true
Series [Int]   // Same as []int
Series [Bool]  // Same as []bool

type MapFunction added in v0.10.1

type MapFunction func(ele Element, index int) Element

type Number added in v0.11.1

type Number float64

func (Number) Div added in v0.11.1

func (n Number) Div(s Series) Series

func (Number) Mod added in v0.11.1

func (n Number) Mod(s Series) Series

func (Number) Sub added in v0.11.1

func (n Number) Sub(s Series) Series

type RollingSeries added in v0.11.5

type RollingSeries interface {
	// Max return the biggest element in the rolling series
	Max() Series
	// Min return the lowest element in the rolling series
	Min() Series
	// Mean calculates the average value of the rolling series
	Mean() Series
	// Mean calculates the weighted average value of the rolling series
	MeanByWeights(weights []float64) Series
	// Quantile returns the quantile of the window of the rolling series.
	Quantile(p float64) Series
	// Quantiles can be computed in batches.
	Quantiles(ps ...float64) []Series
	// QuantileRolling scrolls to calculate the quantile in the rolling series.
	// the p's element corresponds to the window of the rolling series one by one.
	QuantileRolling(p Series) Series
	// DataQuantile scrolls to calculate the current data's quantile in the rolling series.
	// the data's element corresponds to the window of the rolling series one by one.
	DataQuantileRolling(data Series) Series
	// Median calculates the middle or median value of the rolling series
	Median() Series
	// StdDev calculates the standard deviation of the rolling series
	StdDev() Series
	// Apply applies a function for the rolling series
	Apply(f func(window Series, windowIndex int) interface{}, t Type) Series
	//Iterate iterates the rolling series, the window series is nil when minPeriods is less than the window size
	Iterate(f func(window Series, windowIndex int))
}

RollingSeries defines methods of a rolling series

type RollingWindow added in v0.11.1

type RollingWindow interface {
	HasNext() bool
	NextWindow() Series
}

RollingWindow define rolling window

func NewRollingWindow added in v0.11.1

func NewRollingWindow(s Series, windowSize int) RollingWindow

type Self added in v0.12.2

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

All the operations on it will influence the Series's content.

func (Self) Apply added in v0.12.2

func (s Self) Apply(f func(ele Element, index int))

Apply applies the given function to the element of a Series, will influence the Series's content.

type Series

type Series interface {
	Rolling(window int, minPeriods int) RollingSeries
	// HasNaN checks whether the Series contain NaN elements.
	HasNaN() bool
	// IsNaN returns an array that identifies which of the elements are NaN.
	IsNaN() []bool
	// IsNotNaN returns an array that identifies which of the elements are not NaN.
	IsNotNaN() []bool
	// Compare compares the values of a Series with other elements. To do so, the
	// elements with are to be compared are first transformed to a Series of the same
	// type as the caller.
	Compare(comparator Comparator, comparando interface{}) Series
	// Float returns the elements of a Series as a []float64. If the elements can not
	// be converted to float64 or contains a NaN returns the float representation of
	// NaN.
	Float() []float64
	// Bool returns the elements of a Series as a []bool or an error if the
	// transformation is not possible.
	Bool() ([]bool, error)
	// Int returns the elements of a Series as a []int or an error if the
	// transformation is not possible.
	Int() ([]int, error)
	// Order returns the indexes for sorting a Series. NaN elements are pushed to the
	// end by order of appearance.
	Order(reverse bool) []int
	// StdDev calculates the standard deviation of a series
	StdDev() float64
	// Mean calculates the average value of a series
	Mean() float64
	// Median calculates the middle or median value, as opposed to
	// mean, and there is less susceptible to being affected by outliers.
	Median() float64
	// Max return the biggest element in the series
	Max() float64
	// MaxStr return the biggest element in a series of type String
	MaxStr() string
	// Min return the lowest element in the series
	Min() float64
	// MinStr return the lowest element in a series of type String
	MinStr() string
	// Quantile returns the sample of x such that x is greater than or
	// equal to the fraction p of samples.
	// Note: gonum/stat panics when called with strings
	Quantile(p float64) float64
	Quantiles(ps ...float64) []float64
	// DataQuantile returns the data quantile in the series
	DataQuantile(data float64) float64
	DataQuantiles(datas ...float64) []float64
	// Map applies a function matching MapFunction signature, which itself
	// allowing for a fairly flexible MAP implementation, intended for mapping
	// the function over each element in Series and returning a new Series object.
	// Function must be compatible with the underlying type of data in the Series.
	// In other words it is expected that when working with a Float Series, that
	// the function passed in via argument `f` will not expect another type, but
	// instead expects to handle Element(s) of type Float.
	Map(f MapFunction) Series
	//Shift series by desired number of periods and returning a new Series object.
	Shift(periods int) Series
	// CumProd finds the cumulative product of the first i elements in s and returning a new Series object.
	CumProd() Series
	// Prod returns the product of the elements of the Series. Returns 1 if len(s) = 0.
	Prod() float64
	// AddConst adds the scalar c to all of the values in Series and returning a new Series object.
	AddConst(c float64) Series
	// AddConst multiply the scalar c to all of the values in Series and returning a new Series object.
	MulConst(c float64) Series
	// DivConst Div the scalar c to all of the values in Series and returning a new Series object.
	DivConst(c float64) Series
	Add(c Series) Series
	Sub(c Series) Series
	Mul(c Series) Series
	Div(c Series) Series
	Abs() Series
	// Sum calculates the sum value of a series
	Sum() float64

	Empty() Series
	// Returns Error or nil if no error occured
	Error() error
	// Subset returns a subset of the series based on the given Indexes.
	Subset(indexes Indexes) Series
	// Concat concatenates two series together. It will return a new Series with the
	// combined elements of both Series.
	Concat(x Series) Series
	// Copy will return a copy of the Series.
	Copy() Series
	// Records returns the elements of a Series as a []string
	Records() []string
	// Type returns the type of a given series
	Type() Type
	// Len returns the length of a given Series
	Len() int
	// String implements the Stringer interface for Series
	String() string
	// Str prints some extra information about a given series
	Str() string
	// Val returns the value of a series for the given index. Will panic if the index
	// is out of bounds.
	Val(i int) interface{}
	// Elem returns the element of a series for the given index. Will panic if the
	// index is out of bounds.
	// The index could be less than 0. When the index equals -1, Elem returns the last element of a series.
	Elem(i int) Element
	// Slice slices Series from start to end-1 index.
	Slice(start, end int) Series
	// FillNaN Fill NaN values using the specified value.
	FillNaN(value ElementValue)
	// FillNaNForward Fill NaN values using the last non-NaN value
	FillNaNForward()
	// FillNaNBackward fill NaN values using the next non-NaN value
	FillNaNBackward()
	// CacheAble returns a cacheable series and the returned series's calculation will be cached in case of repeate calculation.
	CacheAble() Series
	// Immutable returns an immutable series and the series can not be modified.
	Immutable() Series
	// Set sets the values on the indexes of a Series and returns the reference
	// for itself. The original Series is modified.
	Set(indexes Indexes, newvalues Series) Series
	// Append adds new elements to the end of the Series. When using Append, the
	// Series is modified in place.
	Append(values interface{})
	Name() string
	SetName(name string)
	SetErr(err error)
	//And logical operation
	And(in interface{}) Series
	//Or logical operation
	Or(in interface{}) Series
	//Not logical operation
	Not() Series

	//Wrap define special operations for multiple Series
	Wrap(ss ...Series) Wrapper
	//When define conditional computation
	When(whenF WhenFilterFunction) When

	//Filter Select the elements that match the FilterFunction
	Filter(ff FilterFunction) Series

	// All the operations on Self will influence the Series's content.
	Self() Self
}

func Bools

func Bools(values interface{}) Series

Bools is a constructor for a Bool Series

func Err added in v0.12.0

func Err(err error) Series

func Floats

func Floats(values interface{}) Series

Floats is a constructor for a Float Series

func Ints

func Ints(values interface{}) Series

Ints is a constructor for an Int Series

func New

func New(values interface{}, t Type, name string) Series

New is the generic Series constructor

func NewDefault added in v0.11.1

func NewDefault(defaultValue interface{}, t Type, name string, len int) Series

func Operation added in v0.11.1

func Operation(operate func(index int, eles ...Element) interface{}, seriess ...Series) (Series, error)

Operation for multiple series calculation

func Strings

func Strings(values interface{}) Series

Strings is a constructor for a String Series

type Type

type Type string

Type is a convenience alias that can be used for a more type safe way of reason and use Series types.

const (
	String Type = "string"
	Int    Type = "int"
	Float  Type = "float"
	Bool   Type = "bool"
)

Supported Series Types

type When added in v0.12.0

type When interface {
	//We do the operation on the elements that satisfy the condition and do nothing on the elements that dose not satisfy the condition.
	Apply(f WhenApplyFunction) Series
}

When defines a conditional computation

type WhenApplyFunction added in v0.12.0

type WhenApplyFunction func(newEle Element, index int)

type WhenFilterFunction added in v0.12.0

type WhenFilterFunction func(ele Element, index int) bool

type Wrapper added in v0.12.0

type Wrapper interface {
	FloatApply(f func(thisValue float64, wrapValues []float64) float64) Series
	BoolApply(f func(thisValue bool, wrapValues []bool) bool) Series
}

Wrapper define special operations for multiple Series

Jump to

Keyboard shortcuts

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