series

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package series provides the Series type, a named typed column of data.

A Series wraps an array with a name and data type, providing a high-level API for column operations. Series are immutable after construction; all mutation operations return new Series values.

All read operations on a Series are safe for concurrent use by multiple goroutines.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DtAccessor

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

DtAccessor provides temporal operations on Date/DateTime/Time/Duration Series.

func (*DtAccessor) Day

func (a *DtAccessor) Day() *Series

Day returns an Int32 Series with the day of month component.

func (*DtAccessor) DayOfYear

func (a *DtAccessor) DayOfYear() *Series

DayOfYear returns an Int32 Series with the day of year (1-366).

func (*DtAccessor) Epoch

func (a *DtAccessor) Epoch(unit string) *Series

Epoch returns an Int64 Series with the epoch value in the given time unit. Supported units: "s" (seconds), "ms" (milliseconds), "us" (microseconds), "ns" (nanoseconds).

func (*DtAccessor) Hour

func (a *DtAccessor) Hour() *Series

Hour returns an Int32 Series with the hour component.

func (*DtAccessor) IsoWeek

func (a *DtAccessor) IsoWeek() *Series

IsoWeek returns an Int32 Series with the ISO week number.

func (*DtAccessor) Minute

func (a *DtAccessor) Minute() *Series

Minute returns an Int32 Series with the minute component.

func (*DtAccessor) Month

func (a *DtAccessor) Month() *Series

Month returns an Int32 Series with the month component (1-12).

func (*DtAccessor) Nanosecond

func (a *DtAccessor) Nanosecond() *Series

Nanosecond returns an Int32 Series with the nanosecond component.

func (*DtAccessor) OffsetBy

func (a *DtAccessor) OffsetBy(duration string) *Series

OffsetBy offsets temporal values by a duration string. Supported formats: "1d", "2mo", "-1y", "3h", etc.

func (*DtAccessor) Quarter

func (a *DtAccessor) Quarter() *Series

Quarter returns an Int32 Series with the quarter (1-4).

func (*DtAccessor) Second

func (a *DtAccessor) Second() *Series

Second returns an Int32 Series with the second component.

func (*DtAccessor) Strftime

func (a *DtAccessor) Strftime(format string) *Series

Strftime formats temporal values using a Go time format string.

func (*DtAccessor) TotalSeconds

func (a *DtAccessor) TotalSeconds() *Series

TotalSeconds returns a Float64 Series with the total duration in seconds. Only applicable to Duration series (microseconds).

func (*DtAccessor) Truncate

func (a *DtAccessor) Truncate(unit string) *Series

Truncate truncates temporal values to the given unit. Supported units: "1h", "1d", "1mo", "1y"

func (*DtAccessor) Weekday

func (a *DtAccessor) Weekday() *Series

Weekday returns an Int32 Series with the weekday (0=Sunday, 6=Saturday).

func (*DtAccessor) Year

func (a *DtAccessor) Year() *Series

Year returns an Int32 Series with the year component.

type Series

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

Series is a named, typed column of data. It wraps an underlying columnar array with a name and provides a rich API for data manipulation.

func New

func New(name string, arr array.Array) *Series

New creates a new Series with the given name and underlying array.

func NewBoolean

func NewBoolean(name string, data []bool) *Series

NewBoolean creates a new Series of boolean values.

func NewBooleanWithValidity

func NewBooleanWithValidity(name string, data []bool, valid []bool) *Series

NewBooleanWithValidity creates a Boolean Series with explicit null tracking.

func NewDate

func NewDate(name string, data []int32) *Series

NewDate creates a new Series of Date values (days since Unix epoch as int32).

func NewDateTime

func NewDateTime(name string, data []int64) *Series

NewDateTime creates a new Series of DateTime values (microseconds since epoch as int64).

func NewDateTimeWithValidity

func NewDateTimeWithValidity(name string, data []int64, valid []bool) *Series

NewDateTimeWithValidity creates a DateTime Series with explicit null tracking.

func NewDateWithValidity

func NewDateWithValidity(name string, data []int32, valid []bool) *Series

NewDateWithValidity creates a Date Series with explicit null tracking.

func NewDuration

func NewDuration(name string, data []int64) *Series

NewDuration creates a new Series of Duration values (microseconds as int64).

func NewDurationWithValidity

func NewDurationWithValidity(name string, data []int64, valid []bool) *Series

NewDurationWithValidity creates a Duration Series with explicit null tracking.

func NewFloat32

func NewFloat32(name string, data []float32) *Series

NewFloat32 creates a new Series of float32 values.

func NewFloat64

func NewFloat64(name string, data []float64) *Series

NewFloat64 creates a new Series of float64 values.

func NewFloat64WithValidity

func NewFloat64WithValidity(name string, data []float64, valid []bool) *Series

NewFloat64WithValidity creates a Float64 Series with explicit null tracking.

func NewInt8

func NewInt8(name string, data []int8) *Series

NewInt8 creates a new Series of int8 values.

func NewInt16

func NewInt16(name string, data []int16) *Series

NewInt16 creates a new Series of int16 values.

func NewInt32

func NewInt32(name string, data []int32) *Series

NewInt32 creates a new Series of int32 values.

func NewInt32WithValidity

func NewInt32WithValidity(name string, data []int32, valid []bool) *Series

NewInt32WithValidity creates an Int32 Series with explicit null tracking.

func NewInt64

func NewInt64(name string, data []int64) *Series

NewInt64 creates a new Series of int64 values.

func NewInt64WithValidity

func NewInt64WithValidity(name string, data []int64, valid []bool) *Series

NewInt64WithValidity creates an Int64 Series with explicit null tracking. Positions where valid[i] is false are marked as null.

func NewString

func NewString(name string, data []string) *Series

NewString creates a new Series of string values.

func NewStringWithValidity

func NewStringWithValidity(name string, data []string, valid []bool) *Series

NewStringWithValidity creates a String Series with explicit null tracking.

func NewTime

func NewTime(name string, data []int64) *Series

NewTime creates a new Series of Time values (nanoseconds since midnight as int64).

func NewTimeWithValidity

func NewTimeWithValidity(name string, data []int64, valid []bool) *Series

NewTimeWithValidity creates a Time Series with explicit null tracking.

func NewUInt8

func NewUInt8(name string, data []uint8) *Series

NewUInt8 creates a new Series of uint8 values.

func NewUInt16

func NewUInt16(name string, data []uint16) *Series

NewUInt16 creates a new Series of uint16 values.

func NewUInt32

func NewUInt32(name string, data []uint32) *Series

NewUInt32 creates a new Series of uint32 values.

func NewUInt64

func NewUInt64(name string, data []uint64) *Series

NewUInt64 creates a new Series of uint64 values.

func (*Series) ArgMax

func (s *Series) ArgMax() (int, bool)

ArgMax returns the index of the maximum non-null value. Returns -1, false if the series is empty or all null.

func (*Series) ArgMin

func (s *Series) ArgMin() (int, bool)

ArgMin returns the index of the minimum non-null value. Returns -1, false if the series is empty or all null.

func (*Series) ArgSort

func (s *Series) ArgSort(descending bool) []int

ArgSort returns the indices that would sort this Series. Nulls are placed at the end.

func (*Series) Array

func (s *Series) Array() array.Array

Array returns the underlying array storage.

func (*Series) BooleanArray

func (s *Series) BooleanArray() *array.BooleanArray

BooleanArray returns the underlying BooleanArray, or nil if wrong type.

func (*Series) Cast

func (s *Series) Cast(target dtype.DataType) (*Series, error)

Cast converts the Series to the target data type. Supported casts:

  • Int64 <-> Float64 (numeric conversion)
  • Int64/Float64 -> String (formatting)
  • String -> Int64/Float64 (parsing, invalid values become null)
  • Boolean -> Int64 (true=1, false=0)
  • Int64 -> Boolean (0=false, nonzero=true)

func (*Series) Count

func (s *Series) Count() int

Count returns the number of non-null values.

func (*Series) CumMax

func (s *Series) CumMax() *Series

CumMax returns a new Series with the cumulative maximum. Only supports Int64 and Float64 types. Other types return nil.

func (*Series) CumMin

func (s *Series) CumMin() *Series

CumMin returns a new Series with the cumulative minimum. Only supports Int64 and Float64 types. Other types return nil.

func (*Series) CumProd

func (s *Series) CumProd() *Series

CumProd returns a new Series with the cumulative product. Only supports Int64 and Float64 types. Other types return nil.

func (*Series) CumSum

func (s *Series) CumSum() *Series

CumSum returns a new Series with the cumulative sum. Only supports Int64 and Float64 types. Other types return nil.

func (*Series) DataType

func (s *Series) DataType() dtype.DataType

DataType returns the data type of the series.

func (*Series) Describe

func (s *Series) Describe() string

Describe returns a summary string with count, mean, std, min, max.

func (*Series) Diff

func (s *Series) Diff(n int) *Series

Diff returns a new Series with the difference between each element and the element n positions before it. The first n values will be null. Only supports Int64 and Float64 types.

func (*Series) DropNulls

func (s *Series) DropNulls() *Series

DropNulls returns a new Series with null values removed.

func (*Series) Dt

func (s *Series) Dt() *DtAccessor

Dt returns a DtAccessor for temporal operations. Returns nil if the Series is not of a temporal type (Date, DateTime, Time, Duration).

func (*Series) Equal

func (s *Series) Equal(other *Series) bool

Equal checks if two series have the same name, type, length, and values.

func (*Series) FillNullFloat64

func (s *Series) FillNullFloat64(fillValue float64) *Series

FillNullFloat64 returns a new Float64 Series with nulls replaced by the given value.

func (*Series) FillNullInt64

func (s *Series) FillNullInt64(fillValue int64) *Series

FillNullInt64 returns a new Int64 Series with nulls replaced by the given value.

func (*Series) FillNullString

func (s *Series) FillNullString(fillValue string) *Series

FillNullString returns a new String Series with nulls replaced by the given value.

func (*Series) Filter

func (s *Series) Filter(mask *bitmap.Bitmap) *Series

Filter returns a new Series containing only elements where mask bits are set.

func (*Series) Float64Values

func (s *Series) Float64Values() []float64

Float64Values returns the underlying float64 slice, or nil if wrong type.

func (*Series) GetBool

func (s *Series) GetBool(i int) (bool, bool)

GetBool returns the boolean value at index i and whether it's valid.

func (*Series) GetFloat64

func (s *Series) GetFloat64(i int) (float64, bool)

GetFloat64 returns the float64 value at index i and whether it's valid.

func (*Series) GetInt32

func (s *Series) GetInt32(i int) (int32, bool)

GetInt32 returns the int32 value at index i and whether it's valid.

func (*Series) GetInt64

func (s *Series) GetInt64(i int) (int64, bool)

GetInt64 returns the int64 value at index i and whether it's valid.

func (*Series) GetString

func (s *Series) GetString(i int) (string, bool)

GetString returns the string value at index i and whether it's valid.

func (*Series) HasNulls

func (s *Series) HasNulls() bool

HasNulls returns true if the series contains any null values.

func (*Series) Head

func (s *Series) Head(n int) *Series

Head returns the first n elements.

func (*Series) Int64Values

func (s *Series) Int64Values() []int64

Int64Values returns the underlying int64 slice, or nil if wrong type.

func (*Series) Interpolate

func (s *Series) Interpolate(method string) *Series

Interpolate fills null values using the specified method. Supported methods: "linear", "pad"/"ffill" (forward fill), "bfill" (backward fill). Only works for numeric types. The "linear" method always returns Float64.

func (*Series) IsDuplicated

func (s *Series) IsDuplicated() *Series

IsDuplicated returns a Boolean Series where true indicates the value at that position appears more than once in the Series.

func (*Series) IsNotNullSeries

func (s *Series) IsNotNullSeries() *Series

IsNotNullSeries returns a Boolean Series where true indicates a non-null in the original.

func (*Series) IsNull

func (s *Series) IsNull(i int) bool

IsNull returns true if the element at index i is null.

func (*Series) IsNullSeries

func (s *Series) IsNullSeries() *Series

IsNullSeries returns a Boolean Series where true indicates a null in the original.

func (*Series) IsValid

func (s *Series) IsValid(i int) bool

IsValid returns true if the element at index i is not null.

func (*Series) Len

func (s *Series) Len() int

Len returns the number of elements in the series.

func (*Series) Max

func (s *Series) Max() (float64, bool)

Max returns the maximum non-null value as a float64. The second return value is false if the series is empty or all null.

func (*Series) Mean

func (s *Series) Mean() (float64, bool)

Mean returns the arithmetic mean of all non-null values. The second return value is false if the series is empty or all null.

func (*Series) Min

func (s *Series) Min() (float64, bool)

Min returns the minimum non-null value as a float64. The second return value is false if the series is empty or all null.

func (*Series) NUnique

func (s *Series) NUnique() int

NUnique returns the number of unique non-null values. This is an O(n) operation that uses a hash set internally.

func (*Series) Name

func (s *Series) Name() string

Name returns the name of the series.

func (*Series) NullCount

func (s *Series) NullCount() int

NullCount returns the number of null elements.

func (*Series) PctChange

func (s *Series) PctChange(n int) *Series

PctChange returns the percentage change between each element and the element n positions before it. Results are Float64. The first n values will be null.

func (*Series) Rank

func (s *Series) Rank(method string) *Series

Rank assigns ranks to the values in the series. Supported methods: "average", "min", "max", "dense", "ordinal". Null values receive null in the output.

func (*Series) Rename

func (s *Series) Rename(name string) *Series

Rename returns a new Series with the given name.

func (*Series) RollingMax

func (s *Series) RollingMax(window int) *Series

RollingMax computes the rolling maximum with the given window size. Returns a Float64 Series. The first (window-1) values are null.

func (*Series) RollingMean

func (s *Series) RollingMean(window int) *Series

RollingMean computes the rolling mean with the given window size. Returns a Float64 Series. The first (window-1) values are null.

func (*Series) RollingMin

func (s *Series) RollingMin(window int) *Series

RollingMin computes the rolling minimum with the given window size. Returns a Float64 Series. The first (window-1) values are null.

func (*Series) RollingStd

func (s *Series) RollingStd(window int) *Series

RollingStd computes the rolling standard deviation with the given window size. Returns a Float64 Series. The first (window-1) values are null.

func (*Series) RollingSum

func (s *Series) RollingSum(window int) *Series

RollingSum computes the rolling sum with the given window size. Returns a Float64 Series. The first (window-1) values are null.

func (*Series) Shift

func (s *Series) Shift(n int) *Series

Shift returns a new Series with values shifted by n positions. Positive n shifts down (introduces nulls at the top). Negative n shifts up (introduces nulls at the bottom).

func (*Series) Slice

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

Slice returns a new Series for the range [start, end).

func (*Series) Sort

func (s *Series) Sort(descending bool) *Series

Sort returns a new Series with elements sorted. Nulls are placed at the end.

func (*Series) Std

func (s *Series) Std() (float64, bool)

Std returns the standard deviation of all non-null values. Uses ddof=1 (sample standard deviation) by default.

func (*Series) StdDDOF

func (s *Series) StdDDOF(ddof int) (float64, bool)

StdDDOF returns the standard deviation with the specified delta degrees of freedom.

func (*Series) Str

func (s *Series) Str() *StrAccessor

Str returns a StrAccessor for string operations. Returns nil if the Series is not of String type.

func (*Series) String

func (s *Series) String() string

String returns a human-readable representation of the series.

func (*Series) StringArray

func (s *Series) StringArray() *array.StringArray

StringArray returns the underlying StringArray, or nil if wrong type.

func (*Series) Sum

func (s *Series) Sum() (float64, bool)

Sum returns the sum of all non-null values as a float64. The second return value is false if the series is empty or all null.

func (*Series) Tail

func (s *Series) Tail(n int) *Series

Tail returns the last n elements.

func (*Series) Take

func (s *Series) Take(indices []int) *Series

Take returns a new Series with elements at the given indices.

func (*Series) TryCast

func (s *Series) TryCast(target dtype.DataType) *Series

TryCast attempts to cast the series to the target type, returning null on failure instead of an error. This is a permissive version of Cast.

func (*Series) Unique

func (s *Series) Unique() *Series

Unique returns a new Series containing only unique values. Order is preserved (first occurrence is kept). Null appears at most once in the result.

func (*Series) Validity

func (s *Series) Validity() *bitmap.Bitmap

Validity returns the null bitmap, or nil if there are no nulls.

func (*Series) Var

func (s *Series) Var() (float64, bool)

Var returns the variance of all non-null values. Uses ddof=1 (sample variance) by default.

func (*Series) VarDDOF

func (s *Series) VarDDOF(ddof int) (float64, bool)

VarDDOF returns the variance with the specified delta degrees of freedom.

type StrAccessor

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

StrAccessor provides string operations on a String Series.

func (*StrAccessor) Capitalize

func (a *StrAccessor) Capitalize() *Series

Capitalize returns a new String Series with the first character of each string uppercased and the rest lowercased.

func (*StrAccessor) Contains

func (a *StrAccessor) Contains(substr string) *Series

Contains returns a Boolean Series indicating whether each string contains substr.

func (*StrAccessor) CountMatches

func (a *StrAccessor) CountMatches(pattern string) *Series

CountMatches counts the number of non-overlapping matches of a regex pattern.

func (*StrAccessor) EndsWith

func (a *StrAccessor) EndsWith(suffix string) *Series

EndsWith returns a Boolean Series indicating whether each string ends with suffix.

func (*StrAccessor) Extract

func (a *StrAccessor) Extract(pattern string, groupIndex int) *Series

Extract extracts the first match of a regex pattern, returning the given group. groupIndex 0 returns the full match; 1+ return capture groups.

func (*StrAccessor) Lengths

func (a *StrAccessor) Lengths() *Series

Lengths returns an Int64 Series with the length (in runes) of each string.

func (*StrAccessor) Pad

func (a *StrAccessor) Pad(width int, side string, fillChar rune) *Series

Pad pads each string to the given width with fillChar. side must be "left", "right", or "both".

func (*StrAccessor) Replace

func (a *StrAccessor) Replace(old, new string) *Series

Replace replaces all occurrences of old with new in each string.

func (*StrAccessor) Slice

func (a *StrAccessor) Slice(start, length int) *Series

Slice extracts a substring from each string using start and length.

func (*StrAccessor) Split

func (a *StrAccessor) Split(sep string, index int) *Series

Split splits each string by the separator and returns a new String Series containing the nth element (0-indexed). If the index is out of range, the value is null.

func (*StrAccessor) StartsWith

func (a *StrAccessor) StartsWith(prefix string) *Series

StartsWith returns a Boolean Series indicating whether each string starts with prefix.

func (*StrAccessor) Strip

func (a *StrAccessor) Strip(chars string) *Series

Strip removes the given characters from both ends of each string.

func (*StrAccessor) ToDatetime

func (a *StrAccessor) ToDatetime(layout string) *Series

ToDatetime parses each string into a DateTime Series using the given Go time layout. Returns a DateTime Series (microseconds since epoch). Unparseable values become null.

func (*StrAccessor) ToLower

func (a *StrAccessor) ToLower() *Series

ToLower returns a new String Series with all characters lowercased.

func (*StrAccessor) ToUpper

func (a *StrAccessor) ToUpper() *Series

ToUpper returns a new String Series with all characters uppercased.

func (*StrAccessor) Trim

func (a *StrAccessor) Trim() *Series

Trim removes leading and trailing whitespace from each string.

func (*StrAccessor) ZFill

func (a *StrAccessor) ZFill(width int) *Series

ZFill pads each string on the left with '0' to the given width.

Jump to

Keyboard shortcuts

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