Module Talon.Col
Column creation and manipulation.
Columns are the building blocks of dataframes, each storing a homogeneous sequence of values with consistent null handling.
The type for columns.
Columns store homogeneous data with consistent null handling:
- Numeric data backed by 1D
Nxtensors with an optional null mask. - String data as
string option array. - Boolean data as
bool option array.
Generic constructors
numeric dtype arr is a numeric column from arr with dtype dtype.
numeric_opt dtype arr is a nullable numeric column from arr with dtype dtype. None values are recorded in the null mask.
From arrays (non-nullable)
Create columns from arrays without introducing null masks. Values are taken literally; to represent missing data, use the _opt constructors instead.
val float32 : float array -> tfloat32 arr is a non-nullable float32 column from arr.
The resulting column has no null mask. All values, including nan, are treated as regular data.
val float64 : float array -> tfloat64 arr is a non-nullable float64 column from arr.
The resulting column has no null mask. All values, including nan, are treated as regular data.
val int32 : int32 array -> tint32 arr is a non-nullable int32 column from arr.
The resulting column has no null mask.
val int64 : int64 array -> tint64 arr is a non-nullable int64 column from arr.
The resulting column has no null mask.
val bool : bool array -> tbool arr is a non-nullable boolean column from arr.
All values are wrapped as Some value, creating a column with no nulls.
val string : string array -> tstring arr is a non-nullable string column from arr.
All values are wrapped as Some value, creating a column with no nulls.
From option arrays (nullable)
Create columns from option arrays with explicit null representation. Numeric types attach a null mask (while storing placeholder values in the tensor), whereas string and boolean types preserve the option structure.
val float32_opt : float option array -> tfloat32_opt arr is a nullable float32 column from arr.
None values are recorded in the null mask. Placeholder nan values are stored in the tensor; callers must rely on the mask (via option accessors or Agg helpers) to detect nulls.
val float64_opt : float option array -> tfloat64_opt arr is a nullable float64 column from arr.
None values are recorded in the null mask. Placeholder nan values are stored in the tensor; callers must rely on the mask to detect nulls.
val int32_opt : int32 option array -> tint32_opt arr is a nullable int32 column from arr.
None values are recorded in the null mask. The tensor stores Int32.min_int as placeholder, but the mask is authoritative when checking for nulls.
val int64_opt : int64 option array -> tint64_opt arr is a nullable int64 column from arr.
None values are recorded in the null mask. The tensor stores Int64.min_int as placeholder, but the mask is authoritative when checking for nulls.
val bool_opt : bool option array -> tbool_opt arr is a nullable boolean column from arr.
The option array is used directly without conversion. O(1).
val string_opt : string option array -> tstring_opt arr is a nullable string column from arr.
The option array is used directly without conversion. O(1).
Properties
val length : t -> intlength col is the number of elements in col.
val null_mask : t -> bool array optionnull_mask col is the null mask of col, if any.
Returns Some mask when an explicit mask was attached via a nullable constructor, None otherwise.
val dtype :
t ->
[ `Float32 | `Float64 | `Int32 | `Int64 | `Bool | `String | `Other ]dtype col is the column's data type as a poly-variant tag.
val is_null_at : t -> int -> boolis_null_at col i is true iff the value at index i is null.
Checks the null mask for numeric columns, or tests for None in string/boolean columns.
From tensors
of_tensor t is a non-nullable column from the 1D tensor t.
The tensor's dtype is preserved. Existing payload values (including NaNs or extremal integers) remain regular data.
Raises Invalid_argument if t is not 1D. O(1) — the tensor is used directly without copying.
Null handling
val has_nulls : t -> boolhas_nulls col is true iff col contains at least one null value.
Checks the null mask for numeric columns, or scans for None in string/boolean columns.
val null_count : t -> intnull_count col is the number of null values in col.
drop_nulls col is col with all null values removed.
The column type is preserved.
fill_nulls col ~value is col with null values replaced by the first element of value.
value must be a single-element column of the same type as col. Raises Invalid_argument if column types don't match.
See also Talon.fill_null for a more convenient scalar-based API at the dataframe level.
Column transforms
diff ?periods col is the element-wise difference between consecutive values. periods defaults to 1.
pct_change ?periods col is the fractional change between consecutive values. nan where the previous value is zero. periods defaults to 1. Result is always float64.
shift ~periods col is col with values shifted by periods positions. Positive shifts move values down (inserting nulls at the top), negative shifts move values up.
Extraction
to_tensor dtype col is the underlying tensor if col is numeric and its dtype matches dtype.
val to_string_array : t -> string option array optionto_string_array col is the underlying string option array if col is a string column.
val to_bool_array : t -> bool option array optionto_bool_array col is the underlying bool option array if col is a boolean column.
val to_string_fn : ?null:string -> t -> int -> stringto_string_fn ?null col is a function that formats the value at index i as a string.
The underlying array is extracted once so repeated calls are O(1). null defaults to "<null>".
val pp : Stdlib.Format.formatter -> t -> unitpp formats a column for inspection. Shows the dtype, length, and up to 5 values.