dataframe

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Package dataframe defines DataFrame, an ordered collection of equal-length Series.

A DataFrame is immutable: every transformation returns a new DataFrame. Where possible, the returned DataFrame shares underlying arrow buffers with the source through reference counting.

Ownership. A DataFrame owns one reference to each of its Series. Column accessors (Column, ColumnAt, Columns) return the owned references directly without cloning. Callers that want a Series to outlive the DataFrame must call Series.Clone themselves. Calling Release on the DataFrame releases its reference to every contained Series; references returned from accessors become invalid at that point unless the caller cloned them.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrColumnNotFound   = errors.New("dataframe: column not found")
	ErrDuplicateColumn  = errors.New("dataframe: duplicate column name")
	ErrHeightMismatch   = errors.New("dataframe: columns have different heights")
	ErrSliceOutOfBounds = errors.New("dataframe: slice out of bounds")
)

Sentinel errors returned by DataFrame operations.

View Source
var (
	ErrJoinKeyDTypeMismatch = fmt.Errorf("dataframe.Join: key dtypes differ")
	ErrJoinUnsupportedKey   = fmt.Errorf("dataframe.Join: unsupported key dtype")
)

Sentinel errors.

View Source
var ErrBadInterval = errors.New("dataframe: invalid interval string")

ErrBadInterval is returned when the interval string cannot be parsed.

View Source
var ErrNotList = errors.New("dataframe: column is not a list")

ErrNotList is returned when Explode is called on a non-list column.

View Source
var ErrNotStruct = errors.New("dataframe: column is not a struct")

ErrNotStruct is returned when Unnest is called on a non-struct column.

View Source
var ErrNotTemporal = errors.New("dataframe: column is not a timestamp")

ErrNotTemporal is returned when Upsample is called on a non-datetime column.

Functions

This section is empty.

Types

type DataFrame

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

DataFrame is an ordered set of equal-length named columns.

func Concat

func Concat(frames ...*DataFrame) (*DataFrame, error)

Concat stacks frames vertically (rows appended). All frames must share identical schemas (column names and dtypes in the same order). Height of the result is the sum of heights; column order matches the first frame.

Mirrors polars pl.concat(..., how="vertical"). On error the caller retains all inputs; on success Concat takes ownership and returns a new DataFrame whose Release drops all internal Series.

For the special case of a single input, Concat returns a Clone so the caller's reference and the return value are independent.

func Empty

func Empty(sch *schema.Schema) *DataFrame

Empty returns an empty DataFrame with the given schema. Every column is zero-length.

func FromArrowTable

func FromArrowTable(t arrow.Table) (*DataFrame, error)

FromArrowTable constructs a DataFrame from an arrow.Table. Each column is wrapped as a single Series; the table's chunk layout is preserved. The returned DataFrame retains references: the caller can Release their table handle independently.

func FromMap

func FromMap(data map[string]any, order []string) (*DataFrame, error)

FromMap builds a DataFrame from a map of column-name to Go slice. Supported slice types: []int64, []int32, []float64, []float32, []string, []bool. This mirrors polars' `pl.DataFrame({"a": [1,2,3]})` ergonomic; Go's map iteration is unordered, so the resulting column order is determined by the `order` argument. Pass nil for insertion-order-agnostic use (keys are sorted lexicographically).

Example:

df, _ := dataframe.FromMap(map[string]any{
    "id":    []int64{1, 2, 3},
    "name":  []string{"a", "b", "c"},
    "value": []float64{1.5, 2.5, 3.5},
}, []string{"id", "name", "value"})

func FromRecord

func FromRecord(rec arrow.RecordBatch) (*DataFrame, error)

FromRecord adapts an arrow RecordBatch. Every column is retained; the caller's reference to rec is unchanged.

func New

func New(cols ...*series.Series) (*DataFrame, error)

New builds a DataFrame from the given columns. All columns must have the same length; duplicate names are rejected. On success New consumes the caller's references to the input Series; callers must not Release them afterward. On error the caller retains ownership.

func (*DataFrame) AllHorizontal

func (df *DataFrame) AllHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

AllHorizontal returns a Boolean Series that is true iff every participating boolean column is true at row i. Non-null-strategy semantics: IgnoreNulls treats null as "not present" (row is true if every non-null input is true); PropagateNulls yields null whenever any input is null.

func (*DataFrame) AnyHorizontal

func (df *DataFrame) AnyHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

AnyHorizontal is the boolean OR analogue of AllHorizontal.

func (*DataFrame) AnyNullMask

func (df *DataFrame) AnyNullMask(_ context.Context) (*series.Series, error)

AnyNullMask returns a boolean Series whose i-th entry is true when ANY column at row i is null. Useful for custom row-level null handling. The returned Series itself never has nulls.

func (*DataFrame) Apply

func (df *DataFrame) Apply(fn func(*series.Series) (*series.Series, error)) (*DataFrame, error)

Apply maps fn over every column of df, returning a new DataFrame built from the transformed columns. Column names and order are preserved. If fn returns an error for any column, Apply releases progress and propagates the error.

func (*DataFrame) BottomK

func (df *DataFrame) BottomK(ctx context.Context, k int, col string) (*DataFrame, error)

BottomK returns the k rows with the smallest values in col.

func (*DataFrame) Clear

func (df *DataFrame) Clear() *DataFrame

Clear returns a DataFrame with the same schema but zero rows.

func (*DataFrame) Clone

func (df *DataFrame) Clone() *DataFrame

Clone returns a DataFrame that shares buffers with the source. Both DataFrames must be Released independently.

func (*DataFrame) Column

func (df *DataFrame) Column(name string) (*series.Series, error)

Column returns the Series with the given name. The returned Series is owned by the DataFrame; do not Release it. Clone if you need independent ownership.

func (*DataFrame) ColumnAt

func (df *DataFrame) ColumnAt(i int) *series.Series

ColumnAt returns the Series at position i. See Column for ownership notes.

func (*DataFrame) ColumnNames

func (df *DataFrame) ColumnNames() []string

ColumnNames returns a fresh slice of the column names in order.

func (*DataFrame) Columns

func (df *DataFrame) Columns() []*series.Series

Columns returns all columns in order. See Column for ownership notes.

func (*DataFrame) Contains

func (df *DataFrame) Contains(name string) bool

Contains reports whether a column of the given name exists.

func (*DataFrame) Corr

func (df *DataFrame) Corr(_ context.Context) (*DataFrame, error)

Corr returns a k-by-k Pearson correlation matrix over the numeric columns of df. The output DataFrame has one row per column, columns matching the input names, plus a leading "" column naming each row. Mirrors polars DataFrame.corr() shape.

func (*DataFrame) CountAll

func (df *DataFrame) CountAll(_ context.Context) (*DataFrame, error)

CountAll returns a one-row DataFrame where each column's value is the count of non-null rows. Unlike Sum/Mean/Min/Max, Count is defined for every dtype and so every column of df appears in the output.

func (*DataFrame) Cov

func (df *DataFrame) Cov(_ context.Context, ddof int) (*DataFrame, error)

Cov returns the k-by-k sample covariance matrix (ddof=1) over the numeric columns. Layout matches Corr.

func (*DataFrame) DTypes

func (df *DataFrame) DTypes() []dtype.DType

DTypes returns a fresh slice of per-column dtypes in column order.

func (*DataFrame) Describe

func (df *DataFrame) Describe(ctx context.Context) (*DataFrame, error)

Describe returns summary statistics for every numeric column: count, null_count, mean, std, min, 25%, 50%, 75%, max. Non-numeric columns are described with count and null_count only (other fields are null).

Mirrors polars' DataFrame.describe(). The output is a new DataFrame with a "statistic" column naming the row.

func (*DataFrame) Drop

func (df *DataFrame) Drop(names ...string) *DataFrame

Drop returns a DataFrame without the named columns. Missing names are ignored. The result shares buffers with the source.

func (*DataFrame) DropBy

func (df *DataFrame) DropBy(sel selector.Selector) *DataFrame

DropBy drops the columns chosen by sel.

func (*DataFrame) DropNulls

func (df *DataFrame) DropNulls(ctx context.Context, cols ...string) (*DataFrame, error)

DropNulls returns a new DataFrame with every row that contains a null in any of the given columns removed. Passing no column names checks every column.

Mirrors polars' DataFrame.drop_nulls(subset=None). The returned frame is a fresh DataFrame; callers must Release it.

func (*DataFrame) Equals

func (df *DataFrame) Equals(other *DataFrame) bool

Equals reports whether two DataFrames have the same column names, dtypes, row count, and element-wise values. Uses Series.Equal for per-column comparison (NaN != NaN convention).

func (*DataFrame) EstimatedSize

func (df *DataFrame) EstimatedSize() int

EstimatedSize returns a best-effort byte count of the underlying arrow buffers. Matches polars' DataFrame.estimated_size (in bytes).

func (*DataFrame) Explode

func (df *DataFrame) Explode(ctx context.Context, col string) (*DataFrame, error)

Explode turns each element of a list-typed column into its own row. Mirrors polars' df.explode.

Null and empty lists each become a single null row in the output (polars' default). Surrounding columns are repeated as needed so the result remains rectangular.

Only variable-length list columns (List<T>, LargeList<T>) are supported for now. FixedSizeList will fall through the same path once a kernel lands for it.

func (*DataFrame) Extend

func (df *DataFrame) Extend(other *DataFrame) (*DataFrame, error)

Extend vertically appends other onto df. Schemas must match (polars-compatible: VStack is the stricter version used for a pre-validated schema; we collapse both into one method with schema equality enforcement). Use Concat for the variadic alternative.

func (*DataFrame) FillNull

func (df *DataFrame) FillNull(value any) (*DataFrame, error)

FillNull returns a new DataFrame where nulls are replaced with value in every column whose dtype is compatible with value's Go type. Columns with incompatible dtypes are cloned unchanged (mirrors polars' behaviour of per-column type coercion). Returns the first error encountered; partial progress is released.

func (*DataFrame) Filter

func (df *DataFrame) Filter(ctx context.Context, mask *series.Series, opts ...FilterOption) (*DataFrame, error)

Filter returns a DataFrame containing only rows where mask[i] is true. The mask must be a boolean Series of the same length as the DataFrame. Null mask entries are treated as false.

Filter runs per-column in parallel via compute.Filter. Each output column is an independent Series owning its own buffers.

func (*DataFrame) Format

func (df *DataFrame) Format(opts FormatOptions) string

Format renders the DataFrame as a box-drawn table, close to polars' repr. Useful in tests and REPL sessions.

func (*DataFrame) Gather

func (df *DataFrame) Gather(ctx context.Context, indices []int) (*DataFrame, error)

Gather returns a DataFrame composed of the rows at the given indices. Negative indices are treated as count-from-end (polars- style). Out-of-range indices return an error.

func (*DataFrame) Glimpse

func (df *DataFrame) Glimpse(nRows int) string

Glimpse returns a compact "peek" string: dtype header plus first few rows per column. Intended for interactive exploration.

func (*DataFrame) GroupBy

func (df *DataFrame) GroupBy(keys ...string) *GroupBy

GroupBy returns a group-by builder keyed on the given columns.

func (*DataFrame) HStack

func (df *DataFrame) HStack(other *DataFrame) (*DataFrame, error)

HStack returns a DataFrame horizontally concatenating this frame and other. Row counts must match; duplicate column names are rejected. Mirrors polars' DataFrame.hstack.

func (*DataFrame) HasColumn

func (df *DataFrame) HasColumn(name string) bool

HasColumn is a symmetric predicate to Contains: polars' users may reach for either name.

func (*DataFrame) Head

func (df *DataFrame) Head(n int) *DataFrame

Head returns the first n rows, or the whole frame if n >= height.

func (*DataFrame) Height

func (df *DataFrame) Height() int

Height returns the number of rows.

func (*DataFrame) IsEmpty

func (df *DataFrame) IsEmpty() bool

IsEmpty reports whether the DataFrame has zero rows (regardless of how many columns it has).

func (*DataFrame) Join

func (df *DataFrame) Join(ctx context.Context, right *DataFrame, on []string, how JoinType, opts ...JoinOption) (*DataFrame, error)

Join combines left and right on the given key columns. on must name columns that exist in both frames with the same dtype. The result has every left column followed by every right column except those named in on. Right-side column names that collide with a left-side name receive a suffix.

Implementation: hash-based single-key join for Phase 2. Multi-key is not supported yet and produces an error.

func (*DataFrame) Limit

func (df *DataFrame) Limit(n int) *DataFrame

Limit is an alias for Head: kept for polars-style symmetry so `df.Limit(10)` reads the same in golars scripts and in polars code.

func (*DataFrame) MaxAll

func (df *DataFrame) MaxAll(ctx context.Context) (*DataFrame, error)

MaxAll is MinAll for maxima.

func (*DataFrame) MaxHorizontal

func (df *DataFrame) MaxHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

MaxHorizontal is the row-wise Max analogue of MinHorizontal.

func (*DataFrame) MeanAll

func (df *DataFrame) MeanAll(ctx context.Context) (*DataFrame, error)

MeanAll is SumAll for arithmetic means.

func (*DataFrame) MeanHorizontal

func (df *DataFrame) MeanHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

MeanHorizontal returns a Float64 Series with row-wise mean. Denominator per row is the number of non-null participants when strategy is IgnoreNulls; with PropagateNulls any null yields a null output.

func (*DataFrame) MedianAll

func (df *DataFrame) MedianAll(ctx context.Context) (*DataFrame, error)

MedianAll returns a one-row DataFrame of column-wise medians.

func (*DataFrame) MinAll

func (df *DataFrame) MinAll(ctx context.Context) (*DataFrame, error)

MinAll returns a one-row DataFrame of column-wise minima (numeric columns only).

func (*DataFrame) MinHorizontal

func (df *DataFrame) MinHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

MinHorizontal returns a Float64 Series with row-wise min. The output is null at row i when every participant at row i is null (IgnoreNulls) or when any participant is null (PropagateNulls).

func (*DataFrame) NullCount

func (df *DataFrame) NullCount() *DataFrame

NullCount returns a new DataFrame with one row: for every column, the count of nulls. The result schema preserves names; dtypes become int64. Mirrors polars' DataFrame.null_count.

func (*DataFrame) NullCountAll

func (df *DataFrame) NullCountAll(_ context.Context) (*DataFrame, error)

NullCountAll returns a one-row DataFrame of per-column null counts.

func (*DataFrame) PartitionBy

func (df *DataFrame) PartitionBy(ctx context.Context, keys ...string) ([]*DataFrame, error)

PartitionBy splits df into one DataFrame per distinct combination of values in keys. The returned slice preserves input order. Every DataFrame in the result must be Released by the caller. Mirrors polars' DataFrame.partition_by(keys).

func (*DataFrame) Pipe

func (df *DataFrame) Pipe(fn func(*DataFrame) (*DataFrame, error)) (*DataFrame, error)

Pipe chains a caller-provided function onto df. Useful for building pipelines without repeatedly unpacking (df, err). Mirrors polars' df.pipe(fn).

func (*DataFrame) Pivot

func (df *DataFrame) Pivot(
	_ context.Context,
	index []string,
	columns string,
	values string,
	agg PivotAgg,
) (*DataFrame, error)

Pivot reshapes a long-form DataFrame into wide form. index names the column(s) kept as row identifiers; columns supplies the column whose distinct values become new output columns; values supplies the column whose cells populate the new columns. agg selects the reduction when multiple rows share an (index, column) tuple.

Mirrors polars' DataFrame.pivot(index=, on=, values=, aggregate_function=).

func (*DataFrame) Release

func (df *DataFrame) Release()

Release drops the DataFrame's reference to every contained Series.

func (*DataFrame) Rename

func (df *DataFrame) Rename(oldName, newName string) (*DataFrame, error)

Rename returns a DataFrame where oldName is replaced by newName.

func (*DataFrame) Reverse

func (df *DataFrame) Reverse(ctx context.Context) (*DataFrame, error)

Reverse returns a DataFrame with rows in reverse order.

func (*DataFrame) Row

func (df *DataFrame) Row(i int) ([]any, error)

Row returns the i-th row as a []any slice, one element per column in schema order. Nulls come through as nil. Intended for debugging and REPL display; per-cell typed access is faster via Column().Chunk(0).

func (*DataFrame) Rows

func (df *DataFrame) Rows() ([][]any, error)

Rows materialises the DataFrame as a slice of row slices. Large DataFrames should prefer streaming access.

func (*DataFrame) Sample

func (df *DataFrame) Sample(ctx context.Context, n int, withReplacement bool, seed uint64) (*DataFrame, error)

Sample returns n rows drawn from df. When withReplacement is false (the typical case) sampling is without replacement and n must be <= Height. seed is deterministic when non-zero; zero draws a fresh seed from crypto-less global rand.

Selected rows keep their original relative order (ascending index). For a random permutation, follow Sample with an explicit shuffle (not yet implemented). Mirrors polars DataFrame.sample(n, with_replacement, seed).

func (*DataFrame) SampleFrac

func (df *DataFrame) SampleFrac(ctx context.Context, fraction float64, withReplacement bool, seed uint64) (*DataFrame, error)

SampleFrac returns a DataFrame of exactly floor(fraction * height) rows drawn without replacement (replacement=true to allow repetition). fraction must be in [0, 1] without replacement, or any non-negative value with replacement. Mirrors polars' df.sample(fraction=).

func (*DataFrame) Schema

func (df *DataFrame) Schema() *schema.Schema

Schema returns the DataFrame schema.

func (*DataFrame) Select

func (df *DataFrame) Select(names ...string) (*DataFrame, error)

Select returns a DataFrame with only the named columns in the order requested. The result shares buffers with the source.

func (*DataFrame) SelectBy

func (df *DataFrame) SelectBy(sel selector.Selector) (*DataFrame, error)

SelectBy projects the columns chosen by sel. Equivalent to df.Select(sel.Apply(df.Schema())...).

func (*DataFrame) Shape

func (df *DataFrame) Shape() (int, int)

Shape returns (height, width).

func (*DataFrame) Shuffle

func (df *DataFrame) Shuffle(ctx context.Context, seed uint64) (*DataFrame, error)

Shuffle returns a DataFrame with the same rows in random order. Equivalent to Sample(ctx, Height(), false, seed).

func (*DataFrame) Slice

func (df *DataFrame) Slice(offset, length int) (*DataFrame, error)

Slice returns a DataFrame of [offset, offset+length) rows. Buffers are shared.

func (*DataFrame) Sort

func (df *DataFrame) Sort(ctx context.Context, by string, desc bool, opts ...SortOption) (*DataFrame, error)

Sort returns a new DataFrame sorted by one column. Stable sort.

func (*DataFrame) SortBy

func (df *DataFrame) SortBy(ctx context.Context, keys []string, so []compute.SortOptions, opts ...SortOption) (*DataFrame, error)

SortBy returns a new DataFrame sorted by the given columns with per-column options.

func (*DataFrame) StdAll

func (df *DataFrame) StdAll(ctx context.Context) (*DataFrame, error)

StdAll returns a one-row DataFrame of column-wise sample standard deviations (ddof=1), matching polars' default.

func (*DataFrame) String

func (df *DataFrame) String() string

String returns a polars-style box-drawn table repr. Uses DefaultFormatOptions; call Format for custom bounds.

func (*DataFrame) SumAll

func (df *DataFrame) SumAll(ctx context.Context) (*DataFrame, error)

SumAll returns a one-row DataFrame where each numeric column's value is the sum of that column in df. Non-numeric columns are dropped (matching polars' DataFrame.sum() which keeps only numerics). Mirrors polars' pl.DataFrame.sum().

func (*DataFrame) SumHorizontal

func (df *DataFrame) SumHorizontal(ctx context.Context, strategy NullStrategy, cols ...string) (*series.Series, error)

SumHorizontal returns a Series whose i-th value is the sum of row i across the specified columns (all numeric columns when cols is empty). Null handling follows strategy.

Fast path: when every input is the same numeric dtype with no nulls, the reduction uses compute.Add pairwise (SIMD where available) and the result preserves the input dtype, matching polars' behaviour. Mixed dtypes or nulls fall back to a float64 scalar loop.

func (*DataFrame) Summary

func (df *DataFrame) Summary() string

Summary returns the one-line "dataframe [H x W] schema{...}" shape the previous String() produced. Kept for compact log output.

func (*DataFrame) Tail

func (df *DataFrame) Tail(n int) *DataFrame

Tail returns the last n rows.

func (*DataFrame) ToArrow

func (df *DataFrame) ToArrow() arrow.RecordBatch

ToArrow returns the DataFrame as an arrow.RecordBatch. Each column emits its first chunk. The returned RecordBatch shares memory with the DataFrame: Retain if you need it to outlive this DataFrame. Callers that want a multi-batch view should use ToArrowTable.

func (*DataFrame) ToArrowTable

func (df *DataFrame) ToArrowTable() arrow.Table

ToArrowTable returns the DataFrame as an arrow.Table (a multi-chunk, multi-column view). This is the format most cross-language Arrow IPC tools expect.

func (*DataFrame) ToMap

func (df *DataFrame) ToMap() (map[string][]any, error)

ToMap returns a map[string][]any representation. Useful for JSON roundtripping and quick assertions in tests; costs a full materialisation.

func (*DataFrame) TopK

func (df *DataFrame) TopK(ctx context.Context, k int, col string) (*DataFrame, error)

TopK returns a DataFrame containing the k rows with the largest values in col. Ties are broken by input order (stable sort). k <= 0 returns an empty frame. Mirrors polars' DataFrame.top_k(k, by=col).

func (*DataFrame) Transpose

func (df *DataFrame) Transpose(_ context.Context, headerCol, colPrefix string) (*DataFrame, error)

Transpose returns a DataFrame that is the transpose of df. All columns must share a numeric dtype; the output has one column per row of the input. `headerCol` names the first output column that carries the original column names; `colPrefix` is used to name the resulting columns ("0", "1", ... when colPrefix is empty).

Mirrors polars' DataFrame.transpose(include_header=False, header_name=headerCol, column_names=None) for numeric input.

func (*DataFrame) Unique

func (df *DataFrame) Unique(ctx context.Context) (*DataFrame, error)

Unique returns a DataFrame with duplicate rows removed. Row equality considers every column; the first occurrence of each distinct row wins, preserving input order.

Implementation: single-column int64 and float64 inputs go through a direct hash-dedup (~3-4x faster than the generic groupby path since it skips the per-group Agg machinery). Everything else falls back to GroupBy-with-no-aggs, which is equivalent in semantics.

func (*DataFrame) Unnest

func (df *DataFrame) Unnest(ctx context.Context, col string) (*DataFrame, error)

Unnest replaces a struct-typed column with its fields promoted to top-level columns. Mirrors polars' df.unnest.

Each struct field becomes a top-level Series whose name is taken from the field. Name collisions with an existing column return ErrDuplicateColumn. The struct column itself is removed from the result; surrounding columns keep their relative position.

The struct-level null bitmap (if any) is OR-ed into each child's validity so "row i is null on the struct as a whole" becomes "row i is null in every unnested child", matching polars.

func (*DataFrame) Unpivot

func (df *DataFrame) Unpivot(_ context.Context, idVars []string, valueVars []string) (*DataFrame, error)

Unpivot reshapes df from wide to long form. idVars stay as-is; each other column becomes two rows of a long frame: a "variable" column holding the original column name and a "value" column holding the cell value. Mirrors polars' DataFrame.unpivot (melt in pandas).

func (*DataFrame) Upsample

func (df *DataFrame) Upsample(ctx context.Context, col string, every string) (*DataFrame, error)

Upsample returns a frame with rows interpolated at a regular interval between the first and last values of the named timestamp column. Missing time slots get null values for every other column. Mirrors polars' df.upsample for scalar intervals.

The timestamp column must be sorted ascending; Upsample does not sort for you. Supported interval units: "ns", "us"/"μs", "ms", "s", "m", "h", "d". Month/year intervals are rejected because they are calendar-dependent.

Example: df.Upsample(ctx, "ts", "1d") produces a dense daily frame from min(ts) through max(ts), left-joining source rows onto the grid.

func (*DataFrame) VStack

func (df *DataFrame) VStack(other *DataFrame) (*DataFrame, error)

VStack is a two-argument alias for Concat(df, other).

func (*DataFrame) VarAll

func (df *DataFrame) VarAll(ctx context.Context) (*DataFrame, error)

VarAll returns a one-row DataFrame of column-wise sample variances (ddof=1).

func (*DataFrame) Width

func (df *DataFrame) Width() int

Width returns the number of columns.

func (*DataFrame) WithColumn

func (df *DataFrame) WithColumn(s *series.Series) (*DataFrame, error)

WithColumn appends s if its name is new, or replaces the existing column with that name in place. The column must have the same length as the DataFrame unless the DataFrame is empty of columns. On success WithColumn consumes the caller's reference to s.

func (*DataFrame) WithColumns

func (df *DataFrame) WithColumns(cols ...*series.Series) (*DataFrame, error)

WithColumns returns a DataFrame extended (or overwritten) with the given Series. Any Series whose name already exists replaces the existing column; new names are appended on the right. Mirrors polars' DataFrame.with_columns(*cols): the single-column variant is WithColumn.

func (*DataFrame) WithRowIndex

func (df *DataFrame) WithRowIndex(name string, offset int64) (*DataFrame, error)

WithRowIndex prepends an int64 column named `name` with row numbers starting at `offset`. Polars default is offset=0 and name="index". The returned frame shares every original column by reference.

type FilterOption

type FilterOption func(*filterConfig)

FilterOption configures DataFrame.Filter.

func WithFilterAllocator

func WithFilterAllocator(alloc memory.Allocator) FilterOption

WithFilterAllocator overrides the allocator used while building the filtered output.

type FormatOptions

type FormatOptions struct {
	MaxRows     int // -1 = no row limit
	MaxCols     int // -1 = no column limit
	MaxCellRune int // -1 = no per-cell truncation
}

FormatOptions controls DataFrame pretty-printing.

func DefaultFormatOptions

func DefaultFormatOptions() FormatOptions

DefaultFormatOptions returns the default display settings used by DataFrame.String(). Mirrors polars' default of showing head+tail around an ellipsis for frames taller than 10 rows.

type GroupBy

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

GroupBy is a pending group-by operation that has not been materialized. Call Agg to produce a result DataFrame.

func (*GroupBy) Agg

func (g *GroupBy) Agg(ctx context.Context, aggs []expr.Expr, opts ...GroupByOption) (*DataFrame, error)

Agg materializes the group-by. Each aggregation expression must have the shape col(name).agg() or col(name).agg().alias(output_name), where agg is one of Sum, Mean, Min, Max, Count, NullCount, First, Last.

To aggregate a computed expression, precompute it with WithColumns before grouping.

Agg uses a sort-based algorithm: the input is sorted by the key columns, contiguous runs of equal keys form groups, and each aggregation is applied per group.

type GroupByOption

type GroupByOption func(*groupByConfig)

GroupByOption configures Agg.

func WithGroupByAllocator

func WithGroupByAllocator(alloc memory.Allocator) GroupByOption

WithGroupByAllocator overrides the allocator used by Agg.

type JoinOption

type JoinOption func(*joinConfig)

JoinOption configures Join.

func WithJoinAllocator

func WithJoinAllocator(alloc memory.Allocator) JoinOption

WithJoinAllocator overrides the allocator used while building output columns.

func WithJoinSuffix

func WithJoinSuffix(s string) JoinOption

WithJoinSuffix overrides the suffix applied to right-side columns whose name collides with the left side. Default: "_right".

type JoinType

type JoinType uint8

JoinType selects the join semantics.

const (
	// InnerJoin emits a row only when keys match on both sides.
	InnerJoin JoinType = iota
	// LeftJoin emits every left row; right columns are null when no match.
	LeftJoin
	// CrossJoin is the Cartesian product; key columns are ignored.
	CrossJoin
)

func (JoinType) String

func (j JoinType) String() string

type NullStrategy

type NullStrategy int

NullStrategy controls how horizontal aggregates treat nulls across the participating columns. Ignore skips nulls (polars default); Propagate returns null whenever any input at that row is null.

const (
	// IgnoreNulls skips null values during the reduction.
	IgnoreNulls NullStrategy = iota
	// PropagateNulls emits a null row when any input is null.
	PropagateNulls
)

type PivotAgg

type PivotAgg string

PivotAgg names the reduction polars' DataFrame.pivot applies when multiple rows map to the same (index, column) cell. "first" keeps the first encountered value; "sum"/"mean"/"min"/"max"/"count" aggregate across the group. Unknown values default to "first".

const (
	PivotFirst PivotAgg = "first"
	PivotSum   PivotAgg = "sum"
	PivotMean  PivotAgg = "mean"
	PivotMin   PivotAgg = "min"
	PivotMax   PivotAgg = "max"
	PivotCount PivotAgg = "count"
)

type SortOption

type SortOption func(*sortConfig)

SortOption configures DataFrame.Sort and SortBy.

func WithSortAllocator

func WithSortAllocator(alloc memory.Allocator) SortOption

WithSortAllocator overrides the allocator used for intermediate arrays.

Jump to

Keyboard shortcuts

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