series

package
v0.8.6 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	Eq        Comparator = "==" // Equal
	Neq                  = "!=" // Non equal
	Greater              = ">"  // Greater than
	GreaterEq            = ">=" // Greater or equal than
	Less                 = "<"  // Lesser than
	LessEq               = "<=" // Lesser or equal than
	In                   = "in" // Inside
	IsNaN                = "is NaN"
	IsNotNaN             = "is not NaN"
)

Supported Comparators

Variables

View Source
var (
	ErrEmptyInput             = seriesError{"Input must not be empty"}
	ErrAllNA                  = seriesError{"All Elements are NA"}
	ErrNotMeaningfulForString = seriesError{"Not meaningful for String"}
	ErrSizeDiffer             = seriesError{"Size of Series differs"}
	ErrBounds                 = seriesError{"Input is outside of range."}

	ErrSize = seriesError{"Must be the same length."}

	ErrBoundsVal = func(val interface{}) seriesError {
		return seriesError{err: fmt.Sprintf("Input %v is outside of range", val)}
	}
)

Package wide errors

Functions

func Covariance added in v0.8.2

func Covariance(data1, data2 []float64) (float64, error)

Covariance is a measure of how much two sets of data change

func CovariancePopulation added in v0.8.2

func CovariancePopulation(data1, data2 []float64) (float64, error)

CovariancePopulation covariance for entire population between two float64 slices

func DefaultDatetimeParser added in v0.8.6

func DefaultDatetimeParser(date string) (time.Time, error)

func GeometricMean added in v0.8.2

func GeometricMean(data []float64) float64

GeometricMean finds geometric mean for slice

func Mean added in v0.8.2

func Mean(data []float64) float64

Mean finds the mean of the slice

func Median added in v0.8.2

func Median(data []float64) float64

Median finds the number in slice

func Outliers added in v0.8.2

func Outliers(data []float64) []float64

func ParseDateTimeFormat added in v0.8.2

func ParseDateTimeFormat(date string) (string, error)

ParseDateTimeFormat parse date and returns time format

func Percentile added in v0.8.2

func Percentile(data []float64, percent float64) (float64, int, error)

Percentile finds the relative standing in a slice of floats

func Percentiles added in v0.8.2

func Percentiles(data []float64, percentiles ...float64) ([]float64, []int, error)

Percentiles finds the relative standing

func Quartile added in v0.8.2

func Quartile(data []float64) []float64

Quartile returns the three quartile points from the float64 slice

func SampleVariance added in v0.8.2

func SampleVariance(input []float64) float64

SampleVariance finds the amount of variance within sample float64 slice

func Stats added in v0.8.2

func Stats(data []float64) (count int, min, max, sum, mean float64)

func Sum added in v0.8.2

func Sum(data []float64) float64

Sum finds the sum of elements

func Variance added in v0.8.2

func Variance(input []float64) float64

Variance the amount of population variation in the float64 slice

Types

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.

type DatetimeParserFn added in v0.8.6

type DatetimeParserFn func(date string) (time.Time, error)

type Element added in v0.8.0

type Element interface {
	Set(interface{}) Element
	Copy() Element
	IsNA() bool
	Type() Type
	Val() ElementValue
	String() string
	Int() (int, error)
	Float() float64
	Bool() (bool, error)
	Time() (time.Time, error)
	Addr() string
	Eq(Element) bool
	Neq(Element) bool
	Less(Element) bool
	LessEq(Element) bool
	Greater(Element) bool
	GreaterEq(Element) bool
}

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

func FirstNonNan added in v0.8.2

func FirstNonNan(series Series) (int, Element)

FirstNonNan finds first non NaN Element returns it index and Element itself

func Max added in v0.8.2

func Max(input Series) (max Element, err error)

Max finds the highest Element in Series

func Min added in v0.8.2

func Min(input Series) (min Element, err error)

Min finds the smalest Element in 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 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 Series

type Series struct {
	Name string // The name of the series

	Err       error       // If there are errors they are stored here
	OtherInfo interface{} // OtherInfo for the serie
	// contains filtered or unexported fields
}

Series is a data structure designed for operating on arrays of elements that should comply with a certain type structure. They are flexible enough that can be transformed to other Series types and account for missing or non valid elements. Most of the power of Series resides on the ability to compare and subset Series of different types.

func Bools

func Bools(values interface{}) Series

Bools is a constructor for a Bool 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 NewFromBytes added in v0.8.2

func NewFromBytes(data []byte) Series

NewFromBytes unmarshal Series from MessagePack byte array

func NewWithDatetimeParser added in v0.8.6

func NewWithDatetimeParser(values interface{}, t Type, name string, dtParser DatetimeParserFn) Series

NewWithDatetimeParser is the generic Series constructor with datetime parser

func NewWithOther added in v0.8.2

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

NewWithOther is the genereic Series constructor with otherInfo

func Strings

func Strings(values interface{}) Series

Strings is a constructor for a String Series

func Times added in v0.8.2

func Times(values interface{}) Series

Times is a constructor for Time Series

func (Series) Addr

func (s Series) Addr() []string

Addr returns the string representation of the memory address that store the values of a given Series.

func (*Series) Append

func (s *Series) Append(values interface{})

Append adds new elements to the end of the Series. When using Append, the Series is modified in place.

func (*Series) AppendSeries added in v0.8.4

func (s *Series) AppendSeries(se *Series)

AppendSeries adds elements to the end of the Series.

func (Series) Bool

func (s Series) Bool() ([]bool, error)

Bool returns the elements of a Series as a []bool or an error if the transformation is not possible.

func (Series) Bytes added in v0.8.2

func (s Series) Bytes() ([]byte, error)

Bytes marshals to MessagePack

func (*Series) Combine added in v0.8.2

func (s *Series) Combine(b Series) Series

Combine combines two series equal size series. If element s[i] is not NA takes s[i] overwise b[i]

func (Series) Compare

func (s Series) Compare(comparator Comparator, comparando interface{}) Series

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.

func (Series) Concat

func (s Series) Concat(x Series) Series

Concat concatenates two series together. It will return a new Series with the combined elements of both Series.

func (Series) ConcatNoCopy added in v0.8.4

func (s Series) ConcatNoCopy(x Series) Series

ConcatNoCopy concatenates two series together without copy. It will return a Series with the combined elements of both Series.

func (Series) Copy

func (s Series) Copy() Series

Copy will return a copy of the Series.

func (Series) Covariance added in v0.8.2

func (s Series) Covariance(so Series) (float64, error)

Covariance computes covariance fo both Series

func (Series) CovariancePopulation added in v0.8.2

func (s Series) CovariancePopulation(so Series) (float64, error)

CovariancePopulation computes covariance of entire population between both Series

func (Series) Elem

func (s Series) Elem(i int) Element

Elem returns the element of a series for the given index or nil if the index is out of bounds

func (Series) Empty

func (s Series) Empty() Series

Empty returns an empty Series of the same type

func (Series) Float

func (s Series) Float() []float64

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.

func (Series) GeometricMean added in v0.8.2

func (s Series) GeometricMean() float64

GeometricMean computes geometric mean

func (Series) HasNaN

func (s Series) HasNaN() bool

HasNaN checks whether the Series contain NaN elements.

func (Series) Int

func (s Series) Int() ([]int, error)

Int returns the elements of a Series as a []int or an error if the transformation is not possible.

func (Series) IsNaN added in v0.8.0

func (s Series) IsNaN() []bool

IsNaN returns an array that identifies which of the elements are NaN.

func (Series) Len

func (s Series) Len() int

Len returns the length of a given Series

func (Series) Mean added in v0.8.2

func (s Series) Mean() float64

Mean computes the mean value

func (Series) Median added in v0.8.2

func (s Series) Median() float64

Median computes median value

func (Series) Order added in v0.8.0

func (s Series) Order(reverse bool) []int

Order returns the indexes for sorting a Series. NaN elements are pushed to the end by order of appearance.

func (Series) Outliers added in v0.8.2

func (s Series) Outliers() []float64

func (Series) Percentile added in v0.8.2

func (s Series) Percentile(percent float64) (float64, int, error)

Percentile finds the relative standing in the Series of floats, returns the percentile value and it index

func (Series) Percentiles added in v0.8.2

func (s Series) Percentiles(percentiles ...float64) ([]float64, []int, error)

Percentiles finds percentiles relative standings in the Series returns the percentile values and their indeses

func (Series) Quartile added in v0.8.2

func (s Series) Quartile() Series

Quartile computes three quartile points

func (Series) Records

func (s Series) Records() []string

Records returns the elements of a Series as a []string

func (Series) SampleVariance added in v0.8.2

func (s Series) SampleVariance() float64

SampleVariance finds the amount of variance within sample Series

func (Series) Set

func (s Series) Set(indexes Indexes, newvalues Series) Series

Set sets the values on the indexes of a Series and returns the reference for itself. The original Series is modified.

func (Series) SetValue added in v0.8.2

func (s Series) SetValue(indexes Indexes, val interface{}) Series

func (Series) Slice added in v0.8.2

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

Slice Subset by start and end

func (Series) Stats added in v0.8.2

func (s Series) Stats() (count int, min, max, sum, mean float64)

func (Series) Str

func (s Series) Str() string

Str prints some extra information about a given series

func (Series) String

func (s Series) String() string

String implements the Stringer interface for Series

func (Series) Subset

func (s Series) Subset(indexes Indexes) Series

Subset returns a subset of the series based on the given Indexes.

func (Series) Sum added in v0.8.2

func (s Series) Sum() float64

Sum sums of elements

func (Series) Time added in v0.8.2

func (s Series) Time() ([]time.Time, error)

Time returns the elements of the a Series as a []time.Time or an error if the transition is not possible

func (Series) Type

func (s Series) Type() Type

Type returns the type of a given series

func (Series) Val

func (s Series) Val(i int) (interface{}, error)

Val returns the value of a series for the given index

func (Series) Variance added in v0.8.2

func (s Series) Variance() float64

Variance the amount of population variation in the 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"
	Time   Type = "time"
)

Supported Series Types

Jump to

Keyboard shortcuts

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