Documentation
¶
Overview ¶
Package series provides a generic one-dimensional labeled array with null support.
Series[T] is the fundamental building block for DataFrames. Each DataFrame column is internally represented as a Series.
Key features:
- Generic type-safe implementation using Go generics
- Bit-packed null masks for memory efficiency
- Copy-on-write semantics for predictability
- Thread-safe concurrent reads
- Rich operations: Apply, Filter, aggregations
Null handling:
- Nulls are tracked via a separate bit mask (1 bit per value)
- Operations skip nulls by default
- FillNA and DropNA methods for null handling
Example:
ages := series.New("age", []int64{25, 30, 35}, core.DtypeInt64)
ages.SetNull(1) // Mark index 1 as null
mean := series.Mean(ages) // Skips null, returns (25+35)/2 = 30
Package series provides a generic one-dimensional labeled array.
Index ¶
- func Max[T core.Comparable](s *Series[T]) (T, bool)
- func Mean[T core.NumericType](s *Series[T]) float64
- func Median[T core.NumericType](s *Series[T]) float64
- func Min[T core.Comparable](s *Series[T]) (T, bool)
- func Quantile[T core.NumericType](s *Series[T], q float64) float64
- func Std[T core.NumericType](s *Series[T]) float64
- func Sum[T core.NumericType](s *Series[T]) T
- func Var[T core.NumericType](s *Series[T]) float64
- type Series
- func (s *Series[T]) Apply(fn func(T) T) *Series[T]
- func (s *Series[T]) Copy() *Series[T]
- func (s *Series[T]) Data() []T
- func (s *Series[T]) DropNA() *Series[T]
- func (s *Series[T]) Dtype() core.Dtype
- func (s *Series[T]) FillNA(value T) *Series[T]
- func (s *Series[T]) Filter(fn func(T) bool) *Series[T]
- func (s *Series[T]) Get(i int) (T, bool)
- func (s *Series[T]) GetUnsafe(i int) T
- func (s *Series[T]) HasNulls() bool
- func (s *Series[T]) Index() core.Index
- func (s *Series[T]) IsNull(i int) bool
- func (s *Series[T]) Len() int
- func (s *Series[T]) Name() string
- func (s *Series[T]) NullCount() int
- func (s *Series[T]) NullMask() *bitset.BitSet
- func (s *Series[T]) Set(i int, value T) error
- func (s *Series[T]) SetIndex(idx core.Index)
- func (s *Series[T]) SetNull(i int)
- func (s *Series[T]) Slice(start, end int) *Series[T]
- func (s *Series[T]) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Max ¶
func Max[T core.Comparable](s *Series[T]) (T, bool)
Max returns the maximum value and true, or the zero value and false if all values are null.
func Mean ¶
func Mean[T core.NumericType](s *Series[T]) float64
Mean returns the arithmetic mean of all non-null values in a numeric Series. Returns NaN if all values are null.
func Median ¶
func Median[T core.NumericType](s *Series[T]) float64
Median returns the median of all non-null values. Returns NaN if all values are null.
func Min ¶
func Min[T core.Comparable](s *Series[T]) (T, bool)
Min returns the minimum value and true, or the zero value and false if all values are null.
func Quantile ¶
func Quantile[T core.NumericType](s *Series[T], q float64) float64
Quantile returns the value at the given quantile (0.0 to 1.0). Uses linear interpolation between data points. Returns NaN if all values are null or q is out of range.
func Std ¶
func Std[T core.NumericType](s *Series[T]) float64
Std returns the sample standard deviation of all non-null values. Uses Bessel's correction (divides by n-1). Returns NaN if count < 2.
func Sum ¶
func Sum[T core.NumericType](s *Series[T]) T
Sum returns the sum of all non-null values in a numeric Series. Returns the zero value of T if all values are null.
Types ¶
type Series ¶
type Series[T any] struct { // contains filtered or unexported fields }
Series is a generic one-dimensional labeled array with support for null values. Operations return new Series (copy-on-write semantics).
func NewWithNulls ¶
func NewWithNulls[T any](name string, data []T, dtype core.Dtype, nullMask *bitset.BitSet) *Series[T]
NewWithNulls creates a new Series with a pre-existing null mask.
func (*Series[T]) Apply ¶
Apply applies a function to each non-null element and returns a new Series.
func (*Series[T]) Data ¶
func (s *Series[T]) Data() []T
Data returns a copy of the underlying data slice.
func (*Series[T]) FillNA ¶
FillNA returns a new Series with null values replaced by the given value.
func (*Series[T]) Filter ¶
Filter returns a new Series containing only elements for which fn returns true. Null values are excluded by default.
func (*Series[T]) Get ¶
Get returns the value at position i and a boolean indicating if it's valid (not null). If the value is null, returns the zero value of T and false.
func (*Series[T]) GetUnsafe ¶
GetUnsafe returns the value at position i without null checking. Use only when you're certain the value is not null.