Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,21 @@ polars, torch) keeps its library's own distinction. list_view and large_list_vie
supported: a source refuses them (the Arrow hasher cannot hash them) and a raw ArrowTableStream
holds them as given (ITL-1129).

Dictionary-encoded columns are refused, tags and data alike (developer, November 18, 2026,
ITL-1264: "Say it is not currently supported in orcapod. We MAY support but not immediately in
the plan"; November 19, 2026, ITL-1277: "safe default, though could be inconvenient, is to
reject working with it"). Every column of a stream (tag, data-tag, data, and Orcapod's own
system-tag, source-info, context and meta columns, which only a hand-built table could encode)
whose Arrow type is, or contains, a dictionary (list, list-view or fixed-size list item, struct
child, map key or item, run-end-encoded values, extension storage) raises InputValidationError naming each such
column with its role, its type and its decoded type (arrow_utils.decode_dictionaries), then
the pyarrow and polars ways to decode. One rule, schema_utils.dictionary_columns with
schema_utils.dictionary_columns_error, applied by ArrowTableStream.__init__ (every source
and operator result) and first by SourceStreamBuilder.build (before the key columns and the
hash); never check it elsewhere. A library value in a cell (a pandas or polars data frame with
a categorical column) is an extension column, not a dictionary, and is accepted. Supporting
dictionary columns later is ITL-1277.

Respect the Arrow types the inputs already have, normalized to their large variants (developer,
November 10, 2026: large and non-large variants hash identically, so always normalize to large
for consistency). Infer an Arrow type from Python values only when no Arrow type is known, and
Expand Down Expand Up @@ -1310,21 +1325,20 @@ data. The rules:
Python's precision (`time64[ns]` within a microsecond, `date64` on one day) are separate
groups. A list-valued tag sorts through `(is_null, value)` pairs at every depth (`_sort_key`:
Polars puts a null inside a list first). The sort frame only sees prepared columns
(`_polars_ready`: a logical type as its storage, a dictionary decoded in one place,
`_without_dictionary`, a temporal value as its integer, `float16` as `float32`, a view as
(`_polars_ready`: a logical type as its storage, a temporal value as its integer, `float16` as `float32`, a view as
its large variant, `decimal256` as four 64-bit limbs, which Polars cannot read (it panics,
which no caller can catch), every list kind, fixed-size lists included, as a large list
over its prepared values). What may reach it is one rule, `_unorderable_part` (an integer,
float, decimal, boolean, string, binary, date, time, timestamp, duration or null, through
logical storage, dictionary values and lists of every kind at every depth), checked from
logical storage and lists of every kind at every depth; no dictionary, since no stream
carries one, ITL-1264), checked from
the schema at validation and from the table when grouping (the async path skips
validation); anything else is refused, never passed through. The output is built from the input's Arrow table: `take()` in the
sorted order and list arrays from group offsets (`arrow_utils.aggregated_list_array`, the
array-based sibling of `build_aggregated_table`), so every key and list element is a value
a member holds, bit for bit (`time64[ns]` keeps its nanoseconds, a float32 signaling NaN
its bits; ITL-1248 for `GroupBy`). The hashes read a float's bits, so a group emits, for
each float key column (a logical type stored as a float, or a dictionary over floats,
included), its members' value with the smallest bit pattern at the column's own width
each float key column (a logical type stored as a float included), its members' value with the smallest bit pattern at the column's own width
(`0.0` over `-0.0`, a positive NaN over a negative one; a signaling NaN has smaller bits
than the canonical quiet NaN, so it wins): never the first row's, never chosen by
`member_order`. Every other key is the group's first member's (equal values are identical).
Expand Down
24 changes: 19 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,21 @@ polars, torch) keeps its library's own distinction. `list_view` and `large_list_
supported: a source refuses them (the Arrow hasher cannot hash them) and a raw `ArrowTableStream`
holds them as given (ITL-1129).

Dictionary-encoded columns are refused, tags and data alike (developer, November 18, 2026,
ITL-1264: "Say it is not currently supported in orcapod. We MAY support but not immediately in
the plan"; November 19, 2026, ITL-1277: "safe default, though could be inconvenient, is to
reject working with it"). Every column of a stream (tag, data-tag, data, and Orcapod's own
system-tag, source-info, context and meta columns, which only a hand-built table could encode)
whose Arrow type is, or contains, a dictionary (list, list-view or fixed-size list item, struct
child, map key or item, run-end-encoded values, extension storage) raises `InputValidationError` naming each such
column with its role, its type and its decoded type (`arrow_utils.decode_dictionaries`), then
the pyarrow and polars ways to decode. One rule, `schema_utils.dictionary_columns` with
`schema_utils.dictionary_columns_error`, applied by `ArrowTableStream.__init__` (every source
and operator result) and first by `SourceStreamBuilder.build` (before the key columns and the
hash); never check it elsewhere. A library value in a cell (a pandas or polars data frame with
a categorical column) is an extension column, not a dictionary, and is accepted. Supporting
dictionary columns later is ITL-1277.

Respect the Arrow types the inputs already have, normalized to their large variants (developer,
November 10, 2026: large and non-large variants hash identically, so always normalize to large
for consistency). Infer an Arrow type from Python values only when no Arrow type is known, and
Expand Down Expand Up @@ -1357,21 +1372,20 @@ data. The rules:
Python's precision (`time64[ns]` within a microsecond, `date64` on one day) are separate
groups. A list-valued tag sorts through `(is_null, value)` pairs at every depth (`_sort_key`:
Polars puts a null inside a list first). The sort frame only sees prepared columns
(`_polars_ready`: a logical type as its storage, a dictionary decoded in one place,
`_without_dictionary`, a temporal value as its integer, `float16` as `float32`, a view as
(`_polars_ready`: a logical type as its storage, a temporal value as its integer, `float16` as `float32`, a view as
its large variant, `decimal256` as four 64-bit limbs, which Polars cannot read (it panics,
which no caller can catch), every list kind, fixed-size lists included, as a large list
over its prepared values). What may reach it is one rule, `_unorderable_part` (an integer,
float, decimal, boolean, string, binary, date, time, timestamp, duration or null, through
logical storage, dictionary values and lists of every kind at every depth), checked from
logical storage and lists of every kind at every depth; no dictionary, since no stream
carries one, ITL-1264), checked from
the schema at validation and from the table when grouping (the async path skips
validation); anything else is refused, never passed through. The output is built from the input's Arrow table: `take()` in the
sorted order and list arrays from group offsets (`arrow_utils.aggregated_list_array`, the
array-based sibling of `build_aggregated_table`), so every key and list element is a value
a member holds, bit for bit (`time64[ns]` keeps its nanoseconds, a float32 signaling NaN
its bits; ITL-1248 for `GroupBy`). The hashes read a float's bits, so a group emits, for
each float key column (a logical type stored as a float, or a dictionary over floats,
included), its members' value with the smallest bit pattern at the column's own width
each float key column (a logical type stored as a float included), its members' value with the smallest bit pattern at the column's own width
(`0.0` over `-0.0`, a positive NaN over a negative one; a signaling NaN has smaller bits
than the canonical quiet NaN, so it wins): never the first row's, never chosen by
`member_order`. Every other key is the group's first member's (equal values are identical).
Expand Down
34 changes: 34 additions & 0 deletions changelog.d/ITL-1264.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
### Breaking changes and migration

- A dictionary-encoded column is refused (ITL-1264, ITL-1277). Dictionary-encoded columns are
not currently supported in Orcapod, tags and data alike. A column whose Arrow type is a
`dictionary`, or holds one inside it, raises `InputValidationError` when a source or a
stream is built. This covers a tag, a data-tag and a data column, and a dictionary inside a
list, a list view or a struct field. The message names each such column with its role, its
type and the type it decodes to, and says how to decode it.
- Before, a dictionary tag was accepted and failed later and far from the cause: in
`as_table(all_info=True)`, a filter, `Batch`, `GroupBy` or a join. Or it ran through a job.
A dictionary data column was accepted with the Python type `Any`, which a typed function
refused and some filters and joins failed on.
- Such columns come from an Arrow table of your own, a pandas `Categorical` of strings, and a
polars `Categorical` or `Enum`. Decode the column first:
- with pyarrow, cast the column to the fully decoded type the error message gives. For a
plain dictionary column that is `column.type.value_type`. For a struct with a dictionary
field it is, for example, `pa.struct([("k", pa.string()), ("n", pa.int64())])`.
- three kinds need a step first: a dictionary whose values hold a dictionary (decode the
top level of each chunk with `dictionary_decode()`, then cast), a list view (cast it to a
large list of the decoded items) and a run-end-encoded column (cast its values, then
expand the runs with `pyarrow.compute.run_end_decode`). The troubleshooting page gives
each call.
- with polars, `df = df.with_columns(pl.col(name).cast(pl.String))`.

When you replace the column, keep its field
(`table.set_column(i, field.with_type(decoded), column)`), so its nullability and
metadata stay. Or keep a data frame whole as a value in a cell: a data frame in a cell (a
library value) is not a dictionary column and is accepted as before.

### Changed

- `GroupBy` no longer reads a dictionary-encoded float key by the bits of its values, as
ITL-1234 describes. Such a key is now refused when its source or stream is built, so that
branch is removed.
2 changes: 1 addition & 1 deletion docs/concepts/operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ cache keys:
When the members of a group hold a float key with different bits (`0.0` and `-0.0`, or NaN
with another sign or payload), the group emits the one with the smallest bit pattern at
the column's own width (`float16`, `float32` or `float64`; a logical type stored as a
float is read through its storage, a dictionary-encoded float through its values), for
float is read through its storage), for
each key column: `0.0` over `-0.0`, and a positive NaN over a negative one. A signaling
NaN has smaller bits than the canonical quiet NaN, so when a member holds one, it is the
key emitted. The emitted key is always a value a member holds, bit for bit, and neither
Expand Down
78 changes: 78 additions & 0 deletions docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,84 @@ logical types are kept, and the two variants hash identically, so no hash depend
one you gave. The Arrow `list_view` and `large_list_view` types are not supported: a source
refuses a column of either type.

Dictionary-encoded columns are not currently supported in Orcapod, tags and data alike. A
column whose Arrow type is a `dictionary`, or holds one inside it (a list of dictionary values,
a struct with a dictionary field), is refused with `InputValidationError` when the source or
stream is built. The message names every such column with its role (tag, data-tag or data), its
type and the type it decodes to, then says how to decode it. Such columns come from an Arrow
table of your own, a pandas `Categorical` of strings, or a polars `Categorical` or `Enum`; CSV
files, Delta tables, database tables and Python values never give one. If keeping the encoding
is not important, decode the column before building the source:

```python
import pyarrow as pa

from orcapod.errors import InputValidationError
from orcapod.sources import ArrowTableSource

coded = pa.table(
{
"session": pa.array(["s1", "s2", "s1"]).dictionary_encode(),
"trial": [1, 1, 2],
"response": pa.array([0.4, 0.7, 0.5]).dictionary_encode(),
}
)
try:
ArrowTableSource(coded, tag_columns=["session", "trial"], tag_only_columns=True)
except InputValidationError as exc:
print("\n".join(str(exc).splitlines()[:3]))
# dictionary-encoded columns are not currently supported in Orcapod:
# - tag column 'session' has type dictionary<values=string, indices=int32, ordered=0> (decoded: string)
# - data column 'response' has type dictionary<values=double, indices=int32, ordered=0> (decoded: double)

decoded = coded
for name in ("session", "response"):
field = decoded.schema.field(name)
value_type = field.type.value_type
# The field keeps its name, nullability and metadata; set_column returns a new table.
decoded = decoded.set_column(
decoded.schema.get_field_index(name),
field.with_type(value_type),
decoded[name].cast(value_type),
)
source = ArrowTableSource(decoded, tag_columns=["session", "trial"], tag_only_columns=True)
print(source.as_table().schema.field("session").type)
# large_string
```

With polars, `pl.col("session").cast(pl.String)` decodes a `Categorical` or `Enum` column.
With pandas, `astype` with the categories' dtype decodes a `Categorical` of strings. Both
return a new frame or column: keep it before building the source.

```python
import pandas as pd
import polars as pl

from orcapod.sources import DataFrameSource

frame = pl.DataFrame({"session": ["s1", "s2", "s1"], "trial": [1, 1, 2]}).with_columns(
pl.col("session").cast(pl.Categorical())
)
frame = frame.with_columns(pl.col("session").cast(pl.String))
print(DataFrameSource(frame, tag_columns=["session"], tag_only_columns=True).keys())
# (('session',), ('trial',))

table = pd.DataFrame({"session": ["s1", "s2", "s1"], "trial": [1, 1, 2]})
table["session"] = table["session"].astype("category")
table["session"] = table["session"].astype(table["session"].cat.categories.dtype)
print(DataFrameSource(table, tag_columns=["session"], tag_only_columns=True).keys())
# (('session',), ('trial',))
```

A pandas `Categorical` of integers that holds a missing value cannot be cast to an integer
dtype this way (fill or drop the missing values first). A pandas `Categorical` of integers
reaches the source as plain integers, so it needs no decoding.

A data frame kept whole as a value in a cell (a pandas or polars `DataFrame` holding a
categorical column) is not a dictionary column: it is a library value, stored and hashed as one
(see [Arrays and other library values](arrays.md)), and is accepted. Supporting
dictionary-encoded columns themselves is future work (ITL-1277).

### SpiralDB tables

`SpiralDBTableSource` exposes a table in a [SpiralDB](https://spiraldb.com) project as a
Expand Down
37 changes: 37 additions & 0 deletions docs/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,43 @@ it an explicit schema (for example `data_schema=` on `DictSource`).

**Fix.** Leave at least one column out of `tag_columns`. A stream needs something to carry.

### `InputValidationError: dictionary-encoded columns are not currently supported in Orcapod: - tag column '...' has type dictionary<...> (decoded: ...)`

**Cause.** A column, tag or data, is dictionary-encoded, or holds a dictionary inside it (for
example a list of dictionary values). This comes from an Arrow table built with
`dictionary_encode()`, a pandas `Categorical` of strings, or a polars `Categorical` or `Enum`.
Orcapod does not support such columns yet; the message names every one, with its role and the
type it decodes to.

**Fix.** Decode the column before building the source.

With pyarrow, keep the field's name, nullability and metadata, and keep the table that
`set_column` returns:

- Take the field: `field = table.schema.field(name)`.
- Take the decoded type: `decoded = field.type.value_type`. For a column that holds a
dictionary inside it (a struct with a dictionary field, a list of dictionary values), use
the decoded type the message gives instead, for example
`pa.struct([("k", pa.string()), ("n", pa.int64())])`.
- Replace the column:
`table = table.set_column(table.schema.get_field_index(name), field.with_type(decoded), table[name].cast(decoded))`.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

Three kinds of column cannot be cast to their decoded type at once, so they need a step
first (each recipe is tested in `tests/test_core/sources/test_dictionary_columns_refused.py`):

- A dictionary whose values hold a dictionary: decode the top level of each chunk first,
`pa.chunked_array([chunk.dictionary_decode() for chunk in column.chunks]).cast(decoded)`.
- A list view: cast it to a large list of the decoded items,
`column.cast(pa.large_list(<decoded item type>))` (a source refuses list views whatever they
hold).
- A run-end-encoded column: cast its values, then expand its runs, chunk by chunk:
`pc.run_end_decode(pa.RunEndEncodedArray.from_arrays(chunk.run_ends, chunk.values.cast(<decoded value type>)))`.

With polars, keep the frame `with_columns` returns:
`df = df.with_columns(pl.col(name).cast(pl.String))`. Or keep the data frame as a value in a cell:
a pandas or polars `DataFrame` stored whole in one column is a library value, not a dictionary
column. See [Arrow types of a source](concepts/sources.md#arrow-types-of-a-source).

### `TypeError: 'PosixPath' object is not iterable` from `CSVSource`

**Cause.** `CSVSource` was given a `pathlib.Path` and no `source_id`. The file path is
Expand Down
Loading
Loading