Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
132 commits
Select commit Hold shift + click to select a range
4205619
docs(plans): plan stage 1 of ITL-1466, three nested row ids (ITL-1471)
eywalker Nov 26, 2026
e64c73c
feat(nodes): define the entry, instance and record ids in one module …
eywalker Nov 26, 2026
f5cdbc8
feat(nodes)!: key rows by instance and record id; layouts pdb_v2, odb…
eywalker Nov 26, 2026
eba3220
test(golden): pin a pipeline table's instance ids; the approved golde…
eywalker Nov 26, 2026
01024ff
docs: the three row ids, the v2 layouts and the changelog fragment (I…
eywalker Nov 26, 2026
8308b01
docs: name the pipeline row key in two comments (ITL-1471)
eywalker Nov 26, 2026
756facb
test(pipeline): accept either async outcome for two copies of one inp…
eywalker Nov 26, 2026
b556376
docs: name ITL-1482 where the SQLite refusal of an operator cache is …
eywalker Nov 26, 2026
e45e75f
test: regression tests for the review findings on the row ids (ITL-1471)
eywalker Nov 26, 2026
941cf04
fix(nodes): a placeholder on the async route finds its result by the …
eywalker Nov 26, 2026
27b28ce
fix(provenance): a trace resolves a held row by its instance (ITL-1471)
eywalker Nov 26, 2026
8fe95b8
fix(datagrams): the instance id reads a row's typed token columns (IT…
eywalker Nov 26, 2026
a2803ea
docs: the Arrow hash summary names the three ids; rules for tokens, t…
eywalker Nov 26, 2026
2d8a6a8
test(pipeline): build the inactive pod through the decorator (ITL-1471)
eywalker Nov 26, 2026
086e70f
test(pipeline): a stored row recomputes its ids whatever its token co…
eywalker Nov 26, 2026
1f39198
fix(nodes): a pipeline row stores the token columns its instance id w…
eywalker Nov 26, 2026
6fe86ef
test, docs: ordinary rows keep their stored token columns; rows with …
eywalker Nov 26, 2026
f5a7bf0
fix(nodes): a row with no token stores no token column (ITL-1471)
eywalker Nov 26, 2026
5d1ebee
Merge branch 'main' into eywalker/itl-1471-three-nested-row-ids-v2-ta…
eywalker Nov 26, 2026
f3f6842
test(pipeline): name ITL-1491 on the tests that pin the held-rows dif…
eywalker Nov 26, 2026
df42f2d
test: regression tests for the second review of the row ids (ITL-1471)
eywalker Nov 26, 2026
fba3aec
fix(nodes): key the pipeline table by node content hash and record id…
eywalker Nov 26, 2026
ab58159
fix(provenance): select a held row's record by its instance id on eve…
eywalker Nov 26, 2026
2747f25
test, docs: the pipeline table's key, the trace by instance id and th…
eywalker Nov 26, 2026
69d8ec1
docs(hashing): list the pipeline table's key in the hash site invento…
eywalker Nov 26, 2026
5f8eba1
test: one canonical type per token value (ITL-1471)
eywalker Nov 26, 2026
296e877
fix(datagrams): one canonical type per token value; a clear refusal f…
eywalker Nov 26, 2026
4a916ec
fix(nodes): read the stored token types with the preflight's one sche…
eywalker Nov 26, 2026
fdd265c
test(pipeline): a fatal error in a placeholder's lookup gives the sam…
eywalker Nov 26, 2026
ddfc24b
fix(nodes): the async route reports the crash of a placeholder row be…
eywalker Nov 26, 2026
6607424
test(datagrams): a missing token is a null token; a kept token keeps …
eywalker Nov 26, 2026
e851695
fix(datagrams): a missing token is a null token, and a changed row ke…
eywalker Nov 26, 2026
027d908
docs(reference): where the row ids are read, when a new instance comp…
eywalker Nov 26, 2026
d72bc9d
test: review items of PR #583 (which record wins, several instance id…
eywalker Nov 26, 2026
20797df
test(pipeline): compare stored instance ids as a set, the async route…
eywalker Nov 26, 2026
3e90d4d
test(datagrams): a rename moves a column's token with it in every vie…
eywalker Nov 26, 2026
5edd6e3
fix(datagrams): a rename carries only the tokens of the columns the r…
eywalker Nov 26, 2026
03d7abe
test: a fall-through token has one type on both routes and from the s…
eywalker Nov 26, 2026
fd94fb7
fix(datagrams): a column taken from another row has its token typed f…
eywalker Nov 26, 2026
9b65574
test(datagrams): a rename of a placeholder keeps its sentinel tokens …
eywalker Nov 26, 2026
9361884
fix(datagrams): an empty rename returns the row itself, and a placeho…
eywalker Nov 26, 2026
52f2560
feat(row_ids)!: the record id covers the node's content hash and is t…
eywalker Nov 26, 2026
262a0cc
docs(datagrams): the re-typing of a fallen-through data-tag's token i…
eywalker Nov 27, 2026
3298bf5
docs(datagrams): state the token re-typing stopgap exactly, without o…
eywalker Nov 27, 2026
07ca350
test: source-info token columns keep the pipeline's type on the sync …
eywalker Nov 27, 2026
fb8c01e
fix: a source-info token column keeps the pipeline's type on every ro…
eywalker Nov 27, 2026
3577548
Merge branch 'eywalker/itl-1471-three-nested-row-ids-v2-table-layouts…
eywalker Nov 27, 2026
994e658
docs(datagrams): cut the token re-typing stopgap text down to what th…
eywalker Nov 27, 2026
ac1f269
Merge branch 'eywalker/itl-1471-three-nested-row-ids-v2-table-layouts…
eywalker Nov 27, 2026
2907816
test: the findings of the independent review of PR 601, failing befor…
eywalker Nov 27, 2026
d698ea9
fix: token types on the Join's async route, record batches, hand-buil…
eywalker Nov 27, 2026
749ddf5
docs: say only what holds for token types, and state when a refusal m…
eywalker Nov 27, 2026
65c1965
test: a Join never stores its pending marker in a merged token, faili…
eywalker Nov 27, 2026
47b146e
chore: types in the review fixes and tests (ITL-1491)
eywalker Nov 27, 2026
a13e53f
test: a source-info token's layers must be its data's outer layers, f…
eywalker Nov 27, 2026
81582a3
feat(streams): refuse a stream whose source-info token does not have …
eywalker Nov 27, 2026
891a089
test: Index gives the element the declared token type less one layer,…
eywalker Nov 27, 2026
584dbfa
fix(index): the element's token has the declared type less one layer,…
eywalker Nov 27, 2026
789222e
test: row-built form and rows-on-read fixtures give list tokens list …
eywalker Nov 27, 2026
6c61599
test: session and data-tag token fixtures follow the token-shape rule…
eywalker Nov 27, 2026
37beb11
test: stored-row and row-id token fixtures follow the token-shape rul…
eywalker Nov 27, 2026
f5685cd
fix(streaming joins): a batch is held to its stream's token type; fix…
eywalker Nov 27, 2026
b94dc7f
test: channel, record-batch and transport fixtures follow the token-s…
eywalker Nov 27, 2026
0d2f1c7
test: end-to-end and equivalence token fixtures follow the token-shap…
eywalker Nov 27, 2026
838f948
test: the review findings restated under the token-shape rule; the Jo…
eywalker Nov 27, 2026
94ae454
docs: the token-shape rule, two declarations of one token column, and…
eywalker Nov 27, 2026
dca30c9
chore: types in the token-shape test helpers (ITL-1491)
eywalker Nov 27, 2026
76f5398
test: the last hand-built token fixture follows the token-shape rule;…
eywalker Nov 27, 2026
5bd029e
test: the findings of the second review of PR 601, failing before the…
eywalker Nov 27, 2026
128c38a
fix: a string leaf in the token-shape rule, held rows on the async ro…
eywalker Nov 27, 2026
79fd36d
docs: token rules match what is checked and where; the ordinary-sourc…
eywalker Nov 27, 2026
04de92a
test: the findings of the third review of PR 601, failing before thei…
eywalker Nov 27, 2026
05b5ce8
fix: the held-row check reads one normalized form and a row's token l…
eywalker Nov 27, 2026
7b32524
test: a token's list is never null at any level; guards for input no …
eywalker Nov 27, 2026
6c1c9d6
fix: a token's list is never null at any level, checked where a strea…
eywalker Nov 27, 2026
159da25
test: the findings of the fourth review of PR 601, failing before the…
eywalker Nov 27, 2026
ab8a94b
fix: take the async held-row check out; the rule is checked where a s…
eywalker Nov 27, 2026
e4af3a2
docs: say which Index outcome the aside means; state the ITL-1534 lim…
eywalker Nov 27, 2026
ce0cc26
chore: merge main into ITL-1491
eywalker Nov 27, 2026
789c1a2
fix(arrow): declare Join system tags non-nullable and validate source…
eywalker Nov 27, 2026
08d2c67
fix(sources): reject missing custom system tag columns (ITL-1543)
eywalker Nov 27, 2026
969ed09
fix(arrow): honor Join field declarations and validate raw source rea…
eywalker Nov 27, 2026
705d60b
fix(streams): preserve declared system tag fields in rows (ITL-1543)
eywalker Nov 28, 2026
88fd5de
Merge remote-tracking branch 'origin/main' into eywalker/itl-1543-part-b
eywalker Nov 28, 2026
d74dd59
fix(streams): reconcile system tag fields across source and Join path…
eywalker Nov 28, 2026
5ac1301
Merge remote-tracking branch 'origin/main' into eywalker/itl-1543-part-b
eywalker Nov 28, 2026
376bdb6
fix(streams): declare source-info token fields nullable (ITL-1557)
eywalker Nov 28, 2026
0c9b2b8
chore(branch): merge ITL-1543 part B into ITL-1557
eywalker Nov 28, 2026
5d3f24b
fix(streams): validate replayed source tags and share tied Join sorti…
eywalker Nov 28, 2026
ab136d0
fix(sources): validate Arrow exporters before Polars conversion (ITL-…
eywalker Nov 28, 2026
4ca8850
fix(streams): use shared token fields for empty sinks
eywalker Nov 28, 2026
cc249b0
chore(branch): merge updated ITL-1543 part B
eywalker Nov 28, 2026
d902f4e
test(sources): expect refusal of integer system tags (ITL-1543)
eywalker Nov 28, 2026
1f210fd
Merge branch 'eywalker/itl-1543-a-row-must-take-exactly-its-streams-a…
eywalker Nov 28, 2026
5f518d8
test(datagrams): expect preserved Arrow system tag fields (ITL-1543)
eywalker Nov 28, 2026
ecb9ffb
fix(cache): store declared operator output fields (ITL-1562)
eywalker Nov 28, 2026
f624760
Merge remote-tracking branch 'origin/eywalker/itl-1543-part-b' into e…
eywalker Nov 28, 2026
c62f82a
fix(cache): preserve declared token fields on operator replay
eywalker Nov 28, 2026
4f2a63f
Merge remote-tracking branch 'origin/main' into eywalker/itl-1543-part-b
eywalker Nov 28, 2026
8083d19
Merge remote-tracking branch 'origin/main' into eywalker/itl-1543-part-b
eywalker Nov 28, 2026
403ff6f
fix(provenance): preserve declared types when replacing source tokens
eywalker Nov 28, 2026
a9a3794
chore: merge PR 606 into ITL-1491
eywalker Nov 28, 2026
2486c63
chore: merge main into ITL-1491 after API reference fix
eywalker Nov 28, 2026
7ecc2c4
fix(streams): merge declared token types into the provenance stack
eywalker Nov 28, 2026
42197e9
chore: merge main into the provenance stack
eywalker Nov 28, 2026
87a3b0f
test(cache): type list-valued provenance fixtures
eywalker Nov 28, 2026
864a46f
fix(streams): enforce declared provenance fields at cache and transpo…
eywalker Nov 28, 2026
b4e029e
Merge branch 'main' of https://github.com/metamorphic-labs/orcapod-py…
eywalker Nov 28, 2026
4809ad3
fix(streams): preserve declared fields across async routes
eywalker Nov 28, 2026
b256508
test(async): align placeholder schema with producer
eywalker Nov 28, 2026
cd803c4
fix(sources)!: DataFrameSource accepts data frames only (ITL-1330)
eywalker Nov 28, 2026
cb7c7ae
Merge branch 'main' of https://github.com/metamorphic-labs/orcapod-py…
eywalker Nov 28, 2026
490ebf1
fix(provenance): keep declared fields on source and tag inputs
eywalker Nov 28, 2026
b525d7a
fix(provenance): enforce declared token and system-tag types
eywalker Nov 28, 2026
432c7a6
fix(provenance): refuse a null replacement of a held list token
eywalker Nov 28, 2026
fec02ff
chore(branch): merge main into ITL-1557
eywalker Nov 28, 2026
7280ed1
docs(provenance): clarify null constructor token handling
eywalker Nov 28, 2026
d3cf41b
chore(branch): merge main and enforce typed null token rejection
eywalker Nov 28, 2026
32cc845
Merge remote-tracking branch 'origin/eywalker/itl-1557-re-evaluate-a-…
eywalker Nov 28, 2026
f9eab3c
fix(sources): require declared types for object columns
eywalker Nov 28, 2026
a80c854
chore(sources): merge main into ITL-1330
eywalker Nov 28, 2026
e4d8936
test(sources): pass a frame to the source registration fixture
eywalker Nov 28, 2026
47dc0b5
docs(sources): use typed pandas columns in the list tutorial
eywalker Nov 28, 2026
f05a7ce
fix(sources): preserve declared pandas nulls and explain Arrow refusals
eywalker Nov 28, 2026
52ab9c2
Merge remote-tracking branch 'origin/main' into eywalker/itl-1330-dat…
eywalker Nov 28, 2026
eeea191
fix(sources): restore native casts for declared frame columns
eywalker Nov 28, 2026
cb6449b
fix(sources): preserve native frame conversion and clarify NumPy migr…
eywalker Nov 29, 2026
14e804a
Merge remote-tracking branch 'origin/main' into eywalker/itl-1330-dat…
eywalker Nov 29, 2026
7b658d2
fix(sources): clarify DataFrameSource migration diagnostics
eywalker Nov 29, 2026
d27a13b
Merge remote-tracking branch 'origin/main' into eywalker/itl-1330-dat…
eywalker Nov 29, 2026
39efb58
fix(sources): tailor DataFrameSource refusal guidance to the input
eywalker Nov 29, 2026
e1e286d
fix(sources): give iterators and Series columns working migrations
eywalker Nov 29, 2026
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
14 changes: 12 additions & 2 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,18 @@ data. The rules:
- `-> datetime` is an instant, stored as `timestamp[us, tz=UTC]` (developer, November 21,
2026, ITL-1268; the mapping does not change in data context v1). Every Arrow timestamp
type reads as `datetime`. One rule stores a Python `datetime` the type converter
converts (function outputs at any depth, `DictSource` and `ListSource` values; not a
`DataFrameSource` over a plain dict or list, ITL-1330): `universal_converter.storable_instant`.
converts (function outputs at any depth, `DictSource` and `ListSource` values): `universal_converter.storable_instant`. A
`DataFrameSource` takes data frames only (developer, November 28, 2026, ITL-1330: "we could
expand it in the future if we really need to"): a pandas or Polars `DataFrame`, or an
object exporting an Arrow C stream or C array, whose columns keep their types; a dict, a
list, any other container of Python values, a NumPy array, a `Series` and a `LazyFrame`
are refused when the source is built (`data_frame_source._require_data_frame`, a
`TypeError` naming the type and the remedy), never typed through Polars.
Pandas `object` columns require an explicit `schema=` (ITL-1330). With a schema,
the source uses the existing native frame conversion and Arrow schema cast.
Polars `Object` columns use the existing conversion with or without a schema.
Use a typed pandas datetime column to preserve
precision and timezone through frame conversion.
An aware value of any zone is stored as its exact instant (an offset with a part below
one second is converted to UTC first: Arrow drops that part; any other value is handed to
Arrow as before, so no stored value moves); a naive value raises `NaiveDatetimeError` (strict policy); a
Expand Down
14 changes: 12 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1503,8 +1503,18 @@ data. The rules:
- `-> datetime` is an instant, stored as `timestamp[us, tz=UTC]` (developer, November 21,
2026, ITL-1268; the mapping does not change in data context v1). Every Arrow timestamp
type reads as `datetime`. One rule stores a Python `datetime` the type converter
converts (function outputs at any depth, `DictSource` and `ListSource` values; not a
`DataFrameSource` over a plain dict or list, ITL-1330): `universal_converter.storable_instant`.
converts (function outputs at any depth, `DictSource` and `ListSource` values): `universal_converter.storable_instant`. A
`DataFrameSource` takes data frames only (developer, November 28, 2026, ITL-1330: "we could
expand it in the future if we really need to"): a pandas or Polars `DataFrame`, or an
object exporting an Arrow C stream or C array, whose columns keep their types; a dict, a
list, any other container of Python values, a NumPy array, a `Series` and a `LazyFrame`
are refused when the source is built (`data_frame_source._require_data_frame`, a
`TypeError` naming the type and the remedy), never typed through Polars.
Pandas `object` columns require an explicit `schema=` (ITL-1330). With a schema,
the source uses the existing native frame conversion and Arrow schema cast.
Polars `Object` columns use the existing conversion with or without a schema.
Use a typed pandas datetime column to preserve
precision and timezone through frame conversion.
An aware value of any zone is stored as its exact instant (an offset with a part below
one second is converted to UTC first: Arrow drops that part; any other value is handed to
Arrow as before, so no stored value moves); a naive value raises `NaiveDatetimeError` (strict policy); a
Expand Down
31 changes: 31 additions & 0 deletions changelog.d/ITL-1330.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Breaking changes and migration

- `DataFrameSource` accepts data frames only (ITL-1330): a pandas `DataFrame`, a Polars
`DataFrame`, or an object that exports an Arrow C stream or array of structs (a pyarrow
`Table`, `RecordBatch` or `RecordBatchReader`, a frame of another library). Python
containers, NumPy arrays, pandas and Polars `Series`, Polars `LazyFrame` and non-struct
Arrow exporters raise `TypeError` with the input type and a remedy. Move Python values
to `DictSource` (rows as a list of dicts) or `ListSource` (a list of values), which
type them by Orcapod's rules. Convert a mapping of Python columns to row dictionaries
before passing it to `DictSource`.
To keep Polars' own typing, build the frame yourself:
`DataFrameSource(pl.DataFrame(data), ...)`; a `Series` takes `to_frame()`, a `LazyFrame`
`collect()`. For NumPy values, including tuples and mappings of arrays, or non-struct
Arrow data, build a `pyarrow.Table` with named columns of supported types and pass it
to `ArrowTableSource`. Typed data frames keep the same rows, types, default source id
and hashes. A `DataFrameSource` keeps its data in memory and is never saved, so a loaded
job has no data for its slot until a source is bound.
- Pandas `object` columns require an explicit `schema=`. With a schema, the source uses
the existing frame conversion and Arrow schema cast. Polars `Object` columns use the
existing conversion with or without a schema. Convert a pandas column to a typed
dtype with `astype("string")`, `pd.to_datetime`, or `convert_dtypes()`.
Use a typed datetime column to retain nanoseconds with a
`timestamp[ns]` field.

### Fixed

- A `DataFrameSource` given a dict or a list of Python values no longer types them through
Polars, around Orcapod's rules (ITL-1330): a `pandas.Timestamp` with nanoseconds was
stored as `timestamp[us, tz=UTC]` with the nanoseconds dropped and no error, and a naive
`datetime` as an unzoned `timestamp[us]`, although a `DictSource` refuses both. Such an
input is now refused (above).
7 changes: 3 additions & 4 deletions docs/concepts/function-pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,9 @@ function:
- The same rule holds for a `datetime` inside a list, a dict or a class field, and for the
Python values of a `DictSource` or a `ListSource`. There it raises `NaiveDatetimeError`
or `SubMicrosecondDatetimeError`, both `ValueError`s, and names the value. A
`DataFrameSource` given a plain dict or list is not covered yet: Polars converts the
values before Orcapod sees them, so a naive value is stored without a zone and
nanoseconds are dropped (ITL-1330). Over a real data frame, a `DataFrameSource` keeps
each timestamp column's unit and zone as given.
`DataFrameSource` takes data frames only: given a dict or a list of Python values it
raises `TypeError` and points to `DictSource` and `ListSource`. Over a data frame it
keeps each timestamp column's unit and zone as given.

A function over a column without a zone therefore says which zone its wall times are in:

Expand Down
52 changes: 49 additions & 3 deletions docs/concepts/sources.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,56 @@ hashing) and produces the final immutable stream.
| `ArrowTableSource` | PyArrow `Table` | Accepts an Arrow table directly |
| `DictSource` | `list[dict]` | Each dict becomes one (Tag, Data) pair |
| `ListSource` | `list[Any]` | Each element stored under the data column given by `name`; the tag defaults to `element_index` |
| `DataFrameSource` | Pandas or Polars `DataFrame` | Converts via Arrow |
| `DataFrameSource` | Pandas or Polars `DataFrame`, or an Arrow-exporting object | Data frames only; columns keep their types |
| `CSVSource` | File path (string) | Reads CSV into Arrow |
| `DeltaTableSource` | Directory path | Reads Delta Lake table |

`DataFrameSource` takes a data frame and nothing else: a pandas or Polars `DataFrame`, or an
object that exports an Arrow C stream or C array of structs (a pyarrow `Table`, `RecordBatch` or
`RecordBatchReader`, a frame of another library). Its columns keep the types they have. A
dict, a list or any other container of Python values is refused when the source is built, and
so are a NumPy array, a pandas or Polars `Series` and a Polars `LazyFrame`: Python values go
to `DictSource` or `ListSource`, which type them by Orcapod's rules (a naive `datetime` is
refused there, and nanoseconds are never dropped). Convert a mapping of Python columns to
row dictionaries for `DictSource`. For NumPy data, including tuples and mappings of
arrays, or non-struct Arrow data, build a `pyarrow.Table` with named columns of supported
types and pass it to `ArrowTableSource`. To have Polars infer the types, build a frame
yourself and pass it to `DataFrameSource`.

Pandas `object` columns require an explicit `schema=`. With a schema, the source converts
the frame, discards auxiliary system columns, and casts the Arrow table to the schema.
Polars `Object` columns use the existing conversion with or without a schema.
For example, an object column can lose timestamp precision during frame conversion
before the cast. Use a typed datetime column from `pd.to_datetime` to retain
nanoseconds with a `timestamp[ns]` field. `astype("string")` and `convert_dtypes()`
can also give pandas columns a typed dtype before construction.

```python
import polars as pl

from orcapod.sources import DataFrameSource, DictSource

columns = {"session": ["s1", "s2"], "trial": [1, 2], "rate": [0.5, 0.75]}
try:
DataFrameSource(columns, tag_columns=["session", "trial"])
except TypeError as error:
print(str(error).split(";")[1].split(".")[0].strip())
# got dict

rows = [
{"session": "s1", "trial": 1, "rate": 0.5},
{"session": "s2", "trial": 2, "rate": 0.75},
]
print(DictSource(rows, tag_columns=["session", "trial"], tag_only_columns=True).keys())
# (('session', 'trial'), ('rate',))
print(
DataFrameSource(
pl.DataFrame(columns), tag_columns=["session", "trial"], tag_only_columns=True
).keys()
)
# (('session', 'trial'), ('rate',))
```

`orcapod.sources` also provides database-backed sources (`SQLiteTableSource`,
`PostgreSQLTableSource`, `SpiralDBTableSource`) and `PollingSource` for data that arrives over
time (provisional in this release, see [Provisional sources](#provisional-sources)); see the
Expand Down Expand Up @@ -284,7 +330,7 @@ print(source.as_table().schema.field("session").type)
```

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
With pandas, `astype("string")` decodes a `Categorical` of strings to a typed column. Both
return a new frame or column: keep it before building the source.

```python
Expand All @@ -302,7 +348,7 @@ print(DataFrameSource(frame, tag_columns=["session"], tag_only_columns=True).key

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)
table["session"] = table["session"].astype("string")
print(DataFrameSource(table, tag_columns=["session"], tag_only_columns=True).keys())
# (('session',), ('trial',))
```
Expand Down
44 changes: 44 additions & 0 deletions docs/dev/design_issues/ITL-1330-S6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
## `src/orcapod/core/sources/`

### S6 — A `DataFrameSource` given Python values typed them through Polars, silently lossy
**Status:** resolved
**Severity:** high
**Issue:** ITL-1330

`DataFrameSource` passed whatever it was given to `pl.DataFrame(data)`, so it also built from
a dict or a list of Python values, and Polars inferred the types before the data context's
type converter saw anything. The converter's rules did not apply on that path:

- `DataFrameSource({"id": [1], "v": [pd.Timestamp("2026-01-02T03:04:05.123456789Z")]})`
stored `timestamp[us, tz=UTC]`: 789 nanoseconds dropped, no error.
- A naive `datetime` was stored as an unzoned `timestamp[us]`, while the same value in a
`DictSource` raises `NaiveDatetimeError`.

Anything else Polars can make a frame of built too: a string (one row, a column named
`column_0`), a generator, a NumPy array, a Polars `Series`.

**Fix:** `DataFrameSource` accepts data frames only (developer, November 28, 2026, option
(a): "we could expand it in the future if we really need to"). A data frame is a pandas
`DataFrame`, a Polars `DataFrame`, or an object that exports an Arrow C stream or C array of
a struct (a pyarrow `Table`, `RecordBatch`, `RecordBatchReader`, a struct array, a frame of
another library). Everything else is refused before frame conversion by one rule,
`data_frame_source._require_data_frame`: a `TypeError` that names the type given and its
remedy (`DictSource` / `ListSource`, or `pl.DataFrame(data)` for a
caller who wants Polars' typing, `ArrowTableSource` with named columns for NumPy inputs
including tuples and mappings of arrays, `to_frame()` for a `Series`, and `collect()`
for a `LazyFrame`).
Mixed NumPy and Python row iterators can pass `pl.DataFrame(data).to_arrow()` to
`ArrowTableSource`. Sequences and iterators of Polars Series with distinct names can
pass `pa.table({series.name: series for series in data})` to the same source when
their types are supported. Refusing an iterator leaves it available for either migration.
A Polars `Series` exports an Arrow C stream and is excluded explicitly. Every supported input
builds as before (`tests/test_core/sources/test_data_frame_source_inputs.py` pins the default
source id measured before the change).

Pandas `object` columns require an explicit `schema=`. With a schema, the existing
frame conversion discards auxiliary system columns before the Arrow schema cast.
Polars `Object` columns use the existing conversion with or without a schema.
The native conversion can drop nanoseconds from timestamps in pandas object columns
before the cast. A typed `datetime64` column keeps its unit and zone through frame
conversion. The Arrow importer reports non-struct exports with the input type and
points to `ArrowTableSource` with named columns of supported types.
15 changes: 14 additions & 1 deletion docs/dev/scripts/itl_640/q3ii_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ def build(root: Path) -> dict[str, Any]:
out: dict[str, Any] = {}
for label, make in (
("DictSource", lambda: DictSource(ROWS, **kw)),
("DataFrameSource(pandas)", lambda: DataFrameSource(pd.DataFrame(ROWS), **kw)),
(
"DataFrameSource(pandas)",
lambda: DataFrameSource(
pd.DataFrame(ROWS).astype(
{
"k": "string",
"s": "string",
"d": pd.ArrowDtype(pa.date32()),
"li": pd.ArrowDtype(pa.list_(pa.int64())),
}
),
**kw,
),
),
("DataFrameSource(polars)", lambda: DataFrameSource(pl.DataFrame(ROWS), **kw)),
(
"ArrowTableSource(from_pylist)",
Expand Down
2 changes: 1 addition & 1 deletion docs/tutorial/coming-from-pandas-or-polars.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def total_present(counts: list[int]) -> int:
list_frame = pl_units.head(1).select(
"unit", pl.concat_list("n_spikes", pl.lit(None, dtype=pl.Int64)).alias("counts")
)
for frame in (list_frame, pd.DataFrame(list_frame.to_dicts())):
for frame in (list_frame, list_frame.to_pandas(use_pyarrow_extension_array=True)):
source = DataFrameSource(frame, tag_columns=["unit"], tag_only_columns=True)
print(source.output_schema()[1]["counts"] == list[int])
print(total_present.pod(source).as_table()["total"].to_pylist() == pl_units["n_spikes"].head(1).to_list())
Expand Down
Loading
Loading