index

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package index is an internal collection of data structures and methods for constructing and modifying n-level indexes and column headers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ColLevel

type ColLevel struct {
	Name      string
	Labels    []string
	LabelMap  LabelMap
	DataType  options.DataType
	IsDefault bool
}

A ColLevel is a single collection of column labels within a Columns collection, plus label mappings and metadata. It is identical to an index Level except for the Labels, which are a simple []interface{} that do not satisfy the values.Values interface.

func NewColLevel

func NewColLevel(labels []string, name string) ColLevel

NewColLevel returns a Columns level with updated label map.

func NewDefaultColLevel

func NewDefaultColLevel(n int, name string) ColLevel

NewDefaultColLevel creates a column level with range labels (0, 1, 2, ...n) and optional name.

func (ColLevel) Copy

func (lvl ColLevel) Copy() ColLevel

Copy copies a Column Level

func (*ColLevel) Duplicate

func (lvl *ColLevel) Duplicate(n int)

Duplicate extends the level by itself n times and modifies the level in place.

func (ColLevel) Len

func (lvl ColLevel) Len() int

Len returns the number of labels in the column level.

func (*ColLevel) Refresh

func (lvl *ColLevel) Refresh()

Refresh updates all the label mappings value within a column level.

func (*ColLevel) ResetDefault

func (lvl *ColLevel) ResetDefault()

ResetDefault converts a column level in place to an ordered default range []int{0, 1, 2,...n}. It is analogous to Reindex but for columns.

func (*ColLevel) Subset

func (lvl *ColLevel) Subset(positions []int)

Subset subsets the label values in a column level at specified integer positions and modifies the ColLevel in place.

type Columns

type Columns struct {
	NameMap LabelMap
	Levels  []ColLevel
}

Columns is a collection of column levels, plus name mappings.

func CreateMultiCol

func CreateMultiCol(cols [][]string, colNames []string) Columns

CreateMultiCol returns a MultiCol from [][]string

func NewColumns

func NewColumns(levels ...ColLevel) Columns

NewColumns returns a new Columns collection from a slice of column levels.

func NewColumnsFromConfig

func NewColumnsFromConfig(config Config, n int) (Columns, error)

NewColumnsFromConfig returns new Columns with default length n using a config struct.

func NewDefaultColumns

func NewDefaultColumns(n int) Columns

NewDefaultColumns returns a new Columns collection with default range labels (0, 1, 2, ... n).

func (Columns) Copy

func (col Columns) Copy() Columns

Copy returns a deep copy of each column level.

func (*Columns) DropLevel

func (col *Columns) DropLevel(level int) error

DropLevel drops the specified cols level and modifies the DataFrame in place. If there is only one col level remaining, replaces with a new default col level.

func (*Columns) InsertLevel

func (col *Columns) InsertLevel(pos int, labels []string, name string) error

InsertLevel inserts a level into the cols and modifies the DataFrame in place.

func (Columns) Len

func (col Columns) Len() int

Len returns the number of labels in every level of the column.

func (Columns) MaxNameWidth

func (col Columns) MaxNameWidth() int

MaxNameWidth returns the number of characters in the column name with the most characters.

func (Columns) MultiName

func (col Columns) MultiName(column int) []string

MultiName returns the names of the column levels at col

func (Columns) MultiNames

func (col Columns) MultiNames() [][]string

MultiNames returns a slice of the names of the column at every level for every column position.

func (Columns) Name

func (col Columns) Name(column int) string

Name returns the name of the column at col

func (Columns) Names

func (col Columns) Names() []string

Names returns the name of every column by concatenating the labels across every level.

func (Columns) NumLevels

func (col Columns) NumLevels() int

NumLevels returns the number of column levels.

func (*Columns) Refresh

func (col *Columns) Refresh()

Refresh updates the global name map and the label mappings at every level. Should be called after Series selection or index modification

func (*Columns) Subset

func (col *Columns) Subset(colPositions []int)

Subset subsets a Columns with all the column levels located at the specified integer positions and modifies the Columns in place.

func (*Columns) SubsetLevels

func (col *Columns) SubsetLevels(levelPositions []int) error

SubsetLevels modifies the DataFrame in place with only the specified cols levels.

type Config

type Config struct {
	Name            string
	DataType        options.DataType
	Index           interface{}
	IndexName       string
	MultiIndex      []interface{}
	MultiIndexNames []string
	Col             []string
	ColName         string
	MultiCol        [][]string
	MultiColNames   []string
	Manual          bool
}

A Config customizes the construction of an Index or Columns object.

type Elements

type Elements struct {
	Labels    []interface{}
	DataTypes []options.DataType
}

Elements refer to all the elements at the same position across all levels of an index.

type Index

type Index struct {
	Levels  []Level
	NameMap LabelMap
}

An Index is a collection of levels, plus label mappings

func CreateMultiIndex

func CreateMultiIndex(levels []interface{}, names []string, manualMode bool) (Index, error)

CreateMultiIndex creates a multiindex from a slice of interface values representing different levels

func New

func New(levels ...Level) Index

New receives one or more Levels and returns a new Index. Expects that Levels already have .LabelMap and .Longest set.

func NewDefault

func NewDefault(length int) Index

NewDefault creates a new index with one unnamed index level and range labels (0, 1, 2, ...n)

func NewFromConfig

func NewFromConfig(config Config, n int) (Index, error)

NewFromConfig returns a new Index with default length n using a config struct.

func (Index) Aligned

func (idx Index) Aligned() error

Aligned ensures that all index levels have the same length.

func (Index) Copy

func (idx Index) Copy() Index

Copy returns a deep copy of each index level

func (Index) DataTypes

func (idx Index) DataTypes() []options.DataType

DataTypes returns a slice of the DataTypes at each level of the index

func (*Index) DropLevel

func (idx *Index) DropLevel(level int) error

DropLevel drops an index level and modifies the Index in place. If there is only one level, replaces with default index.

func (Index) Elements

func (idx Index) Elements(position int) Elements

Elements returns all the index elements at an integer position.

func (*Index) InsertLevel

func (idx *Index) InsertLevel(pos int, values interface{}, name string) error

InsertLevel inserts a level into the index and modifies the index in place.

func (Index) Len

func (idx Index) Len() int

Len returns the number of labels in every level of the index.

func (Index) MaxWidths

func (idx Index) MaxWidths() []int

MaxWidths returns the max number of characters in each level of an index.

func (Index) NumLevels

func (idx Index) NumLevels() int

NumLevels returns the number of levels in the index.

func (*Index) Refresh

func (idx *Index) Refresh()

Refresh updates the global name map and the label mappings at every level. Should be called after index modification

func (*Index) Set

func (idx *Index) Set(row int, level int, val interface{}) error

Set sets the value at the specified index row and level to val and modifies the Index in place.

func (*Index) Subset

func (idx *Index) Subset(rowPositions []int) error

Subset subsets the index with the labels located at the specified integer positions and modifies the index in place.

func (*Index) SubsetLevels

func (idx *Index) SubsetLevels(levelPositions []int) error

SubsetLevels subsets the index with only the levels located at specified integer positions and modifies the index in place.

func (*Index) SwapLevels

func (idx *Index) SwapLevels(i, j int) error

SwapLevels swaps two levels in the index and modifies the index in place.

func (Index) Unnamed

func (idx Index) Unnamed() bool

Unnamed returns true if all index levels are unnamed

type LabelMap

type LabelMap map[string][]int

A LabelMap records the position of labels, in the form {label name: [label position(s)]}

type Level

type Level struct {
	DataType  options.DataType
	Labels    values.Values
	LabelMap  LabelMap
	Name      string
	IsDefault bool
}

A Level is a single collection of labels within an index, plus label mappings and metadata

func InterpolatedNewLevel

func InterpolatedNewLevel(data interface{}, name string) (Level, error)

InterpolatedNewLevel creates an Index Level and interpolates []interface{}

func MustNewLevel

func MustNewLevel(data interface{}, name string) Level

MustNewLevel returns a new level from an interface, but panics on error

func NewDefaultLevel

func NewDefaultLevel(n int, name string) Level

NewDefaultLevel creates an index level with range labels (0, 1, 2, ...n) and optional name.

func NewLevel

func NewLevel(data interface{}, name string) (Level, error)

NewLevel creates an Index Level from a Scalar or Slice interface{} but returns an error if interface{} is not supported by factory.

func (*Level) Convert

func (lvl *Level) Convert(kind options.DataType) error

Convert an index level from one kind to another in place, then refreshes the LabelMap

func (Level) Copy

func (lvl Level) Copy() Level

Copy copies an Index Level

func (Level) Len

func (lvl Level) Len() int

Len returns the number of labels in the level

func (*Level) Refresh

func (lvl *Level) Refresh()

Refresh updates all the label mappings value within a level.

func (*Level) ToBool

func (lvl *Level) ToBool()

ToBool converts an index level to Bool

func (*Level) ToDateTime

func (lvl *Level) ToDateTime()

ToDateTime converts an index level to DateTime

func (*Level) ToFloat64

func (lvl *Level) ToFloat64()

ToFloat64 converts an index level to Float

func (*Level) ToInt64

func (lvl *Level) ToInt64()

ToInt64 converts an index level to Int

func (*Level) ToInterface

func (lvl *Level) ToInterface()

ToInterface converts an index level to Interface

func (*Level) ToString

func (lvl *Level) ToString()

ToString converts an index level to String

Jump to

Keyboard shortcuts

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