series

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2025 License: MIT Imports: 6 Imported by: 0

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

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.

func Var

func Var[T core.NumericType](s *Series[T]) float64

Var returns the sample variance of all non-null values. Uses Bessel's correction (divides by n-1). Returns NaN if count < 2.

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 New

func New[T any](name string, data []T, dtype core.Dtype) *Series[T]

New creates a new Series from a slice of data. The dtype must match the type T.

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

func (s *Series[T]) Apply(fn func(T) T) *Series[T]

Apply applies a function to each non-null element and returns a new Series.

func (*Series[T]) Copy

func (s *Series[T]) Copy() *Series[T]

Copy returns a deep copy of the Series.

func (*Series[T]) Data

func (s *Series[T]) Data() []T

Data returns a copy of the underlying data slice.

func (*Series[T]) DropNA

func (s *Series[T]) DropNA() *Series[T]

DropNA returns a new Series with null values removed.

func (*Series[T]) Dtype

func (s *Series[T]) Dtype() core.Dtype

Dtype returns the data type of the Series.

func (*Series[T]) FillNA

func (s *Series[T]) FillNA(value T) *Series[T]

FillNA returns a new Series with null values replaced by the given value.

func (*Series[T]) Filter

func (s *Series[T]) Filter(fn func(T) bool) *Series[T]

Filter returns a new Series containing only elements for which fn returns true. Null values are excluded by default.

func (*Series[T]) Get

func (s *Series[T]) Get(i int) (T, bool)

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

func (s *Series[T]) GetUnsafe(i int) T

GetUnsafe returns the value at position i without null checking. Use only when you're certain the value is not null.

func (*Series[T]) HasNulls

func (s *Series[T]) HasNulls() bool

HasNulls returns true if the Series contains any null values.

func (*Series[T]) Index

func (s *Series[T]) Index() core.Index

Index returns the index of the Series.

func (*Series[T]) IsNull

func (s *Series[T]) IsNull(i int) bool

IsNull returns true if the value at position i is null.

func (*Series[T]) Len

func (s *Series[T]) Len() int

Len returns the number of elements in the Series.

func (*Series[T]) Name

func (s *Series[T]) Name() string

Name returns the name of the Series.

func (*Series[T]) NullCount

func (s *Series[T]) NullCount() int

NullCount returns the number of null values in the Series.

func (*Series[T]) NullMask

func (s *Series[T]) NullMask() *bitset.BitSet

NullMask returns a copy of the null mask, or nil if no nulls exist.

func (*Series[T]) Set

func (s *Series[T]) Set(i int, value T) error

Set sets the value at position i and marks it as non-null.

func (*Series[T]) SetIndex

func (s *Series[T]) SetIndex(idx core.Index)

SetIndex sets the index of the Series.

func (*Series[T]) SetNull

func (s *Series[T]) SetNull(i int)

SetNull marks the value at position i as null.

func (*Series[T]) Slice

func (s *Series[T]) Slice(start, end int) *Series[T]

Slice returns a new Series containing elements from start (inclusive) to end (exclusive).

func (*Series[T]) String

func (s *Series[T]) String() string

String returns a string representation of the Series.

Jump to

Keyboard shortcuts

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