Repository navigation
fix(semantic_types)!: refuse a logical type nested in a dict key or value (ITL-1150) #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
eywalker
merged 6 commits into
main
from
eywalker/itl-1150-refuse-a-logical-type-or-native-container
Nov 15, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d7007e7
test(logical_types): failing tests for refusing a logical type nested…
5571561
docs: a logical type nested in a dict is refused at definition (ITL-1…
857ab26
Merge origin/main into ITL-1150
14e93e2
fix(semantic_types)!: refuse a logical type nested in a dict key or v…
6ba37ca
test(semantic_types): a set as a dict value is refused before the Non…
1991a2c
docs(semantic_types): state the tuple-field refusal accurately (ITL-1…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| ### Breaking changes and migration | ||
|
|
||
| #### A logical type or native container as a dict key or value is refused where it is declared (ITL-1150) | ||
|
|
||
| A dictionary is stored as a list of key/value structs, and Arrow cannot hold an extension type | ||
| inside a struct field. A set of a primitive there was stored silently as a plain list: | ||
| `dict[str, set[int]]` read back from `as_source()`, in a downstream pod and in a job loaded in | ||
| another process as `dict[str, list[int]]`, and a source declared with it took the schema | ||
| `dict[str, list[int]]`. Every other logical type in that position (`Path`, `UUID`, a user | ||
| class, `numpy.ndarray`, `list[Path]`, `set[Path]`) was already refused. | ||
|
|
||
| Now any logical type or native container as a dict key or value, at any depth, is refused | ||
| when it is declared: a function pod's parameter or output, a source's declared or inferred | ||
| schema, and a field of a dataclass, an `orcapod.dataclass` or a pydantic model. Refused, for | ||
| example: `dict[str, set[int]]`, `dict[str, set[str]]`, `dict[str, list[set[int]]]`, | ||
| `dict[set[int], int]`, `list[dict[str, set[int]]]`, a dataclass field typed | ||
| `dict[str, set[int]]`. | ||
|
|
||
| A tuple annotation was never accepted by a function pod or a source (registration rejects it | ||
| as an unsupported annotation, and still does). The only path that took a set inside a tuple | ||
| was a direct call of the type converter (`python_schema_to_arrow_schema({"x": tuple[int, set[int]]})`), | ||
| which stored the set as a plain list and now refuses it too. | ||
|
|
||
| The error, `NestedTypeNotStorableError` (a `ValueError`), names the | ||
| column or `Class.field`, the declared type and ITL-1150. | ||
|
|
||
| Migration: hold the set in a dataclass field (a field of a dataclass, an `orcapod.dataclass` | ||
| or a pydantic model keeps `set[int]`, `Path`, `UUID` and the other logical types on every | ||
| read path), or declare the plain type (`dict[str, list[int]]`). No stored data, stored path or | ||
| hash changes: only declarations that used to be accepted are refused. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| """Which nested positions storage can keep a logical type at (ITL-1150). | ||
|
|
||
| A Python ``dict`` is stored as a list of key/value structs and a tuple as a struct (or a | ||
| fixed-size list), and Arrow cannot hold an extension type inside a struct field or a list | ||
| value field. A logical type or a native container (``set[int]``, ``list[set[int]]``) as a | ||
| dict key or value or a tuple field would therefore be stored as its plain storage and read | ||
| back as something else than declared (a set as a list). Until such positions are stored | ||
| faithfully, a declared type with one is refused where it is declared, so no value is stored | ||
| lossily. A field of a user class is not such a position: the class decodes each field by its | ||
| declared type. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| import pyarrow as pa | ||
|
|
||
| _FOLLOW_UP = "ITL-1150" | ||
|
|
||
|
|
||
| class NestedTypeNotStorableError(ValueError): | ||
| """A logical type is declared where storage cannot keep it (ITL-1150).""" | ||
|
|
||
|
|
||
| def require_storable_in_struct_field(arrow_type: pa.DataType) -> None: | ||
| """Refuse a logical type or native container as a dict key or value or a tuple field. | ||
|
|
||
| Args: | ||
| arrow_type: The Arrow type the declared key, value or field type registers as. | ||
|
|
||
| Raises: | ||
| NestedTypeNotStorableError: If ``arrow_type`` is an extension type (a logical type | ||
| or a native container such as ``set[int]``). | ||
| """ | ||
| import pyarrow as pa | ||
|
|
||
| if isinstance(arrow_type, pa.ExtensionType): | ||
| raise NestedTypeNotStorableError( | ||
| f"a value of Arrow extension type {arrow_type.extension_name!r} cannot be a " | ||
| f"dict key or value or a tuple field yet: Arrow cannot hold an extension type " | ||
| f"inside a struct field, so the value would not read back as declared (a set " | ||
| f"would read as a list). Hold it in a dataclass field, where it keeps its type, " | ||
| f"or declare the plain type (e.g. dict[str, list[int]] for " | ||
| f"dict[str, set[int]]). Follow-up: {_FOLLOW_UP}." | ||
| ) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.