packages

table::column

On this page

Typed column storage: one packed List per column plus an optional validity bitmap. A column and a contiguous Array<T, 1> share one buffer, so from_array and to_f64 copy nothing where they can.

Structs

ColumnSource

pub struct Column

One typed column. Nulls are tracked by a validity bitmap; the slot under a null holds a zero value. Columns share their buffers when copied: they are read-only once built.

nabi
let c = table::Column::from([1.5, 2.5, 4.0]);
assert(c.dtype() == table::DType::F64);
let a = try c.to_f64() catch _ { [0.0] };
assert(a.sum() == 8.0);
  • pub fn i64s(xs: List<i64>) -> Column§

    Source

    An i64 column.

  • pub fn f64s(xs: List<f64>) -> Column§

    Source

    An f64 column. NaN is a value, not a null.

  • pub fn bools(xs: List<bool>) -> Column§

    Source

    A bool column.

  • pub fn strs(xs: List<str>) -> Column§

    Source

    A str column.

  • pub fn dates(xs: List<Date>) -> Column§

    Source

    A date column.

  • pub fn datetimes(xs: List<DateTime>) -> Column§

    Source

    A datetime column.

  • pub fn cat(xs: List<str>) -> Column§

    Source

    A categorical column: each distinct string stored once, a u32 code per row.

    nabi
    let c = table::Column::cat(["red", "blue", "red"]);
    assert(c.dtype() == table::DType::Cat);
    assert(c.levels() == ["red", "blue"]);
    
  • pub fn from_array(a: Array<f64, 1>) -> Column§

    Source

    The f64 array a as a column. A contiguous array shares its buffer with the column (no copy), so write to a.copy() instead of a once it is in a table; a strided view is copied.

    nabi
    use core::array::Array;
    let a: Array<f64, 1> = [1.0, 2.0];
    assert(table::Column::from_array(a).len() == 2);
    
  • pub fn from_i64_array(a: Array<i64, 1>) -> Column§

    Source

    The i64 array a as a column, sharing its buffer as from_array does.

  • pub fn from_bool_array(a: Array<bool, 1>) -> Column§

    Source

    The bool array a as a column, sharing its buffer as from_array does.

  • pub fn nulls(t: DType, n: usize) -> Column§

    Source

    n nulls of type t.

  • pub fn from_values(vs: List<Value>, t: DType | none) throws (TableError) -> Column§

    Source

    Cells of one type, Value::Null for a missing one. The type is the first non-null cell's; Int and Float mixed give f64. All-null input gives t (F64 when t is none).

    nabi
    use table::Value;
    let c = try table::Column::from_values([Value::Int(1), Value::Null, Value::Float(2.5)], none) catch _ { table::Column::f64s([]) };
    assert(c.dtype() == table::DType::F64 && c.null_count() == 1);
    
  • pub fn len(self) -> usize§

    Source

    The number of rows.

  • pub fn is_empty(self) -> bool§

    Source

    No rows.

  • pub fn dtype(self) -> DType§

    Source

    The column type.

  • pub fn null_count(self) -> usize§

    Source

    How many rows are null.

  • pub fn is_null(self, i: usize) -> bool§

    Source

    Whether row i is null.

  • pub fn is_valid(self, i: usize) -> bool§

    Source

    Whether row i holds a value.

  • pub fn get(self, i: usize) -> Value§

    Source

    Row i as a cell; Value::Null for a null or i past the end.

  • pub fn values(self) -> List<Value>§

    Source

    The cells in order.

  • pub fn levels(self) -> List<str>§

    Source

    The distinct strings of a Cat column, in code order; empty for other types.

  • pub fn to_f64(self) throws (TableError) -> Array<f64, 1>§

    Source

    The values of a numeric column as an f64 array; i64 converts and nulls read as NaN. An f64 column without nulls shares its buffer with the array (no copy): treat it as read-only, since a write would change every table holding the column, and write to a.copy() instead.

  • pub fn f64_list(self) throws (TableError) -> List<f64>§

    Source

    As to_f64, as a list.

  • pub fn to_i64(self) throws (TableError) -> Array<i64, 1>§

    Source

    The values of an i64 column as an array sharing the column's buffer (read-only, as for to_f64); nulls read as 0.

  • pub fn to_bool(self) throws (TableError) -> Array<bool, 1>§

    Source

    The values of a bool column as an array sharing the column's buffer (read-only, as for to_f64); nulls read as false.

  • pub fn to_strs(self) throws (TableError) -> List<str>§

    Source

    The strings of a str or cat column; nulls read as "".

  • pub fn to_options_i64(self) -> List<i64 | none>§

    Source

    The column with every cell none where it is null.

    nabi
    let c = table::column![1, none, 3];
    assert(c.to_options_i64() == [1, none, 3]);
    
  • pub fn to_options_f64(self) -> List<f64 | none>§

    Source

    As to_options_i64, for numbers as f64.

  • pub fn to_options_str(self) -> List<str | none>§

    Source

    As to_options_i64, for text.

  • pub fn to_cat(self) -> Column§

    Source

    Dictionary-encode a str column (others are returned as they are). Levels keep first-seen order.

  • pub fn cast(self, t: DType) throws (TableError) -> Column§

    Source

    The column as type t. Numbers convert between i64 and f64 (f64 to i64 truncates toward zero; NaN and out-of-range values are an error), anything converts to str, and str parses into the other types (an unparseable cell is an error naming the row).

    nabi
    let c = table::Column::from(["1", "2", "x"]);
    assert((try c.cast(table::DType::I64) catch _ { c }).dtype() == table::DType::Str);
    let n = try table::Column::from(["1", "2"]).cast(table::DType::F64) catch _ { c };
    assert(n.dtype() == table::DType::F64);
    
  • pub fn slice(self, start: usize, end: usize) -> Column§

    Source

    Rows start..end (clamped to the length), sharing the buffer.

  • pub fn take(self, idx: List<usize>) -> Column§

    Source

    The rows at idx, in that order (a gather).

  • pub fn filter(self, mask: List<bool>) -> Column§

    Source

    The rows where mask is true.

  • pub fn concat(self, o: Column) throws (TableError) -> Column§

    Source

    self then o; both must have one type (i64 with f64 gives f64, cat with str gives str).

  • pub fn validity(self) -> List<bool>§

    Source

    One flag per row, true where it holds a value.

Trait implementations 15
  • impl From<List<i64>> for Column
  • impl From<List<f64>> for Column
  • impl From<List<bool>> for Column
  • impl From<List<str>> for Column
  • impl From<List<Date>> for Column
  • impl From<List<DateTime>> for Column
  • impl From<Array<f64, 1>> for Column
  • impl From<Array<i64, 1>> for Column
  • impl From<Array<bool, 1>> for Column
  • impl From<List<i64 | none>> for Column
  • impl From<List<f64 | none>> for Column
  • impl From<List<bool | none>> for Column
  • impl From<List<str | none>> for Column
  • impl PartialEq for Column
  • impl Debug for Column