annie.dataset.manipulate

Browse ‘Manipulate’ transforms — derive a display/filter value per label column.

A label column carries raw CSV text plus a data type (str / int / float, chosen when the CSV is added). The Browse Manipulate block then applies one transform per column, replacing its raw value for tags and filtering:

  • text → trim (strip surrounding whitespace);

  • numeric → round (to the nearest integer, e.g. sentiment 1.0 → 1), threshold (≥X / <X buckets), or sign (negative / zero / positive).

The functions are pure and unit-tested; the UI only wires them up.

Attributes

ColumnType

A column's data type.

TransformKind

A transform a column can carry.

TRANSFORM_LABELS

Short human labels for the transform dropdown.

Classes

Transform

One column's transform.

Functions

transforms_for(→ tuple[TransformKind, ...])

Return the transforms valid for a column type.

detect_type(→ ColumnType)

Guess a column's type from a sample of its (string) values.

apply_transform(→ str)

Apply a column's transform to one raw value, returning its display value.

Module Contents

annie.dataset.manipulate.ColumnType

A column’s data type.

annie.dataset.manipulate.TransformKind

A transform a column can carry.

annie.dataset.manipulate.TRANSFORM_LABELS: dict[TransformKind, str]

Short human labels for the transform dropdown.

class annie.dataset.manipulate.Transform[source]

One column’s transform.

kind

The transform to apply.

threshold

The cut for the threshold transform.

digits

Decimal places for the round transform (default 2).

show_original

Display the untransformed value on the sample rows while the filter still matches on the transformed one. This separates the two jobs a transform does: threshold ≥ 0 on a [-3, 3] sentiment makes a clean two-way filter facet, but the reviewer usually still wants to read the real 1.83 on the row. Purely a display flag — filtering never consults it.

annie.dataset.manipulate.transforms_for(col_type: ColumnType) → tuple[TransformKind, ...][source]

Return the transforms valid for a column type.

annie.dataset.manipulate.detect_type(values: collections.abc.Iterable[str]) → ColumnType[source]

Guess a column’s type from a sample of its (string) values.

Parameters:

values – Sample cell values.

Returns:

"int" if every non-empty value is an integer, "float" if every value is numeric, else "str". An all-empty/absent column defaults to "str".

annie.dataset.manipulate.apply_transform(value: str, col_type: ColumnType, transform: Transform) → str[source]

Apply a column’s transform to one raw value, returning its display value.

A value that cannot be parsed as a number (in a numeric column) is returned unchanged, so a stray non-numeric cell never breaks the row.

Parameters:
  • value – The raw cell text.

  • col_type – The column’s data type.

  • transform – The transform to apply.

Returns:

The transformed string.