Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
f55be45
fix(semantic_types)!: refuse float32 and float16 dict keys and set el…
eywalker Nov 28, 2026
e271151
fix(semantic-types): validate narrow float keys at declarations
eywalker Nov 28, 2026
a2e9a40
fix(semantic_types): validate declarations and preserve blueprint inp…
eywalker Nov 28, 2026
3c01acd
fix(semantic_types): validate remaining narrow float declarations
eywalker Nov 28, 2026
dee15f0
fix(sources): preserve Polars pandas conversion
eywalker Nov 28, 2026
cc4077e
fix(sources): validate pandas Arrow types and restore legacy Delta bi…
eywalker Nov 28, 2026
004557b
fix(sources): validate Arrow imports and preserve legacy job bindings
eywalker Nov 28, 2026
aa89dd7
fix(sources): validate Arrow-backed pandas column iterables
eywalker Nov 28, 2026
ca6c3c1
fix(sources): validate original Arrow declarations without converting…
eywalker Nov 28, 2026
a442fb8
fix(sources): retain Arrow declarations in nested column mappings
eywalker Nov 28, 2026
5d4ddf2
chore: merge main into the narrow-float key fix
eywalker Nov 28, 2026
926881d
fix(semantic-types): reject narrow storage in registered set elements
eywalker Nov 28, 2026
5de7201
fix(semantic-types): preserve inherited and inferred logical sets
eywalker Nov 28, 2026
da3978d
chore(merge): bring main into the narrow float declaration branch
eywalker Nov 28, 2026
22a7fcb
test(semantic-types): type logical test fixtures by their protocol
eywalker Nov 28, 2026
b55bec4
test(semantic-types): register the wide set fixture explicitly
eywalker Nov 28, 2026
9c7326e
test(semantic-types): narrow the wide set fixture converter type
eywalker Nov 28, 2026
60567d6
chore(merge): bring main into the narrow float declaration branch
eywalker Nov 28, 2026
0dc177d
fix(serialization): preserve legacy narrow keys in saved schemas
eywalker Nov 28, 2026
34dcdec
fix(semantic_types): honor logical types in narrow-key checks
eywalker Nov 29, 2026
1034391
chore: merge origin/main into the narrow float key branch
eywalker Nov 29, 2026
7c2fb6f
fix(semantic-types): apply the declared Arrow dict boundary
eywalker Nov 29, 2026
891b361
test(semantic-types): redeclare the public Batch result at a source
eywalker Nov 29, 2026
1a9401b
test(semantic-types): construct the redeclared source from Arrow arrays
eywalker Nov 29, 2026
195bbe4
fix(semantic-types): validate narrow keys at declared boundaries
eywalker Nov 29, 2026
b7fa321
Merge remote-tracking branch 'origin/main' into eywalker/itl-1591-ref…
eywalker Nov 29, 2026
e710fb6
fix(semantic-types): validate Arrow class identity declarations
eywalker Nov 29, 2026
bf6304a
fix(semantic-types): retain narrow literal key validation
eywalker Nov 29, 2026
fcabcb1
test(semantic-types): identify literal key cases explicitly
eywalker Nov 29, 2026
058f44b
chore: merge main into the narrow-float key fix
eywalker Nov 29, 2026
003b2b8
fix(semantic-types): limit narrow-float key checks to Python declarat…
eywalker Nov 29, 2026
aca0cb7
chore: merge main into the Python declaration fix
eywalker Nov 29, 2026
6932a7c
test(sources): type the main Arrow compatibility matrix
eywalker Nov 29, 2026
4a25aa0
fix(function-pods): preserve schemas reconstructed from Arrow
eywalker Nov 29, 2026
754a2f1
docs: reference the narrow-float Arrow follow-up
eywalker Nov 29, 2026
e71d601
Merge remote-tracking branch 'origin/main' into eywalker/itl-1591-ref…
eywalker Nov 29, 2026
a2fbb85
fix(schema): validate narrow float keys at declaration time
eywalker Nov 29, 2026
ea8ba17
fix(schema): honor custom factories in narrow float validation
eywalker Nov 29, 2026
3e2cc4f
chore: merge main into narrow float key validation
eywalker Nov 29, 2026
4e1a354
chore: merge main into narrow float key validation
eywalker Nov 29, 2026
346e6b3
fix(function-pod): use the supplied context for schema validation
eywalker Nov 29, 2026
eb1c049
fix(function-pod): preserve the default function context
eywalker Nov 29, 2026
cb63784
chore: merge main into narrow float key validation
eywalker Nov 29, 2026
8bf2710
chore: merge main into narrow float key validation
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
7 changes: 7 additions & 0 deletions .zed/rules
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,13 @@ data. The rules:
Batch with a size has its own form, grouping rows by arrival. A new operator whose output
rows each come from one input row declares ROW_BY_ROW; write no other per-operator batch
code.
- A Python declaration with a `float32` or `float16` dict key or set element raises
`NarrowFloatKeyError` (ITL-1591, D16, D25 and D41). Narrowing can turn two distinct
keys or elements into one stored value and lose an entry. The check in
`semantic_types/narrow_float_keys.py` reads Python annotations at declaration
boundaries, including native user-class fields at any depth. A registered custom
logical type owns its storage. Inferred types and Arrow inputs use their existing
conversion paths. Plain narrow floats, list elements and dict values are supported.
- The type converter keys synthesized struct classes by the large-normalized struct, so
struct<b: string> and struct<b: large_string> are one Python type (a workaround,
TODO(ITL-841)).
Expand Down
7 changes: 7 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,13 @@ data. The rules:
input (`to_stream()`); `Batch` with a size has its own form, grouping rows by arrival. A new
operator whose output rows each come from one input row declares `ROW_BY_ROW`; write no
other per-operator batch code.
- A Python declaration with a `float32` or `float16` dict key or set element raises
`NarrowFloatKeyError` (ITL-1591, D16, D25 and D41). Narrowing can turn two distinct
keys or elements into one stored value and lose an entry. The check in
`semantic_types/narrow_float_keys.py` reads Python annotations at declaration
boundaries, including native user-class fields at any depth. A registered custom
logical type owns its storage. Inferred types and Arrow inputs use their existing
conversion paths. Plain narrow floats, list elements and dict values are supported.
- The type converter keys synthesized struct classes by the large-normalized struct, so
`struct<b: string>` and `struct<b: large_string>` are one Python type (a workaround,
`TODO(ITL-841)`).
Expand Down
15 changes: 15 additions & 0 deletions changelog.d/ITL-1591.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
### Fixed

- Python declarations of `float32` or `float16` dictionary keys or set elements raise
`NarrowFloatKeyError` in function pods, Python schemas for sources and stream input
slots, datagrams, and explicit Python schemas passed to public converters (ITL-1591).
The check follows nested Python types and stored fields of user classes. Two distinct
values can narrow to one stored value and lose an entry. Declare the key or element
as `float` to retain double precision.

### Known limitations

- Arrow input retains the behavior on main. A declared Arrow field with float32 dict
keys can still narrow `1e-50` and `2e-50` to the same stored key, `0.0`.
Reading that column as a dict raises `RepeatedDictKeyError` (ITL-907).
ITL-1693 tracks the Arrow-input follow-up.
11 changes: 11 additions & 0 deletions docs/concepts/function-pods.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,17 @@ output (ITL-1150). The same types are faithful as a column, inside a list, and a
dataclass, an `orcapod.dataclass` or a pydantic model: hold such a value in a dataclass
field, or declare the plain type (`dict[str, list[int]]`).

A Python declaration of a dictionary key or set element as `np.float32` or
`np.float16` raises `NarrowFloatKeyError` when the pod is defined (ITL-1591).
The check follows nested Python types, including the stored fields of user classes.
Two distinct values can narrow to the same stored value and lose an entry. Declare
the key or element as `float` to retain double precision. Narrow floats are supported
as plain values, list elements and dictionary values.

The same check applies when a source, stream input slot or `Data` declares a Python
schema. Arrow tables and Arrow schemas use the existing Arrow conversion path.
A narrow-float key or set element arriving as Arrow data can still lose an entry.

A pod definition can declare a set of user classes stored as structs. When the first
returned value is converted to native set storage, Orcapod 0.4.0 reports an
`OutputTypeError` for that output. Use `list[T]` to return these values, including inside
Expand Down
5 changes: 5 additions & 0 deletions docs/concepts/logical-type-identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ print(labels_type.storage_type)
`NestedTypeNotStorableError` that names the column or `Class.field` (ITL-1150). Hold the set
in a dataclass field, where it keeps its type, or declare the plain type
(`dict[str, list[int]]`).
- A Python declaration like `set[np.float32]` or `set[np.float16]` raises
`NarrowFloatKeyError` (ITL-1591). Two distinct floats can narrow to one stored
element and lose an entry. Declare `set[float]` to retain double precision.
The same rule applies to Python dictionary keys. Arrow inputs use the existing
Arrow conversion path.
- `frozenset[T]` is not supported: declare `set[T]`. Support is to be evaluated in ITL-1140.

A container type you implement yourself is not a native container. It is an ordinary logical
Expand Down
28 changes: 28 additions & 0 deletions docs/dev/design_issues/ITL-1591-NFK1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## `src/orcapod/semantic_types/universal_converter.py`

### NFK1 — Declared narrow-float dictionary keys and set elements can lose entries
**Status:** resolved
**Severity:** high
**Issue:** ITL-1591 (related: ITL-924, ITL-1613)

Two distinct Python floats can narrow to the same `float32` or `float16` value.
For example, `1e-50` and `2e-50` both become `0.0`. A dict or set read back from
that representation can have fewer entries than the original.

**Fix:** D41 selects fallback (b) for D16 and D25. At a Python declaration boundary,
`semantic_types/narrow_float_keys.py` raises `NarrowFloatKeyError` for a narrow-float
dict key or set element. It checks function pod inputs and outputs, source and
stream slot Python schemas, datagrams, and explicit schemas at public converter
entry points. Row construction and conversion use the existing schema without
running declaration validation. The check follows native container annotations
and stored fields of native user classes, including nested classes. It uses the
converter's write-side factory selection to identify the storage owner before a
codec is built. A custom registration owns its storage from its first declaration.
Plain narrow-float values, list elements and dict values remain supported.

**Known limitations:** Schema-free Python inference and Arrow input retain main's
behavior. Arrow tables, declared Arrow schemas, raw streams, saved schemas and
stored results can still carry these types. For example,
`Data({"id": 1}).with_columns({"k": pa.large_list(pa.struct([("key", pa.float32()), ("value", pa.int64())]))}, k={1e-50: 1, 2e-50: 2})`
stores two keys of `0.0` in Arrow. Reading that column with `as_dict()` raises
`RepeatedDictKeyError` (ITL-907). ITL-1693 tracks the Arrow-input follow-up.
10 changes: 8 additions & 2 deletions src/orcapod/core/cached_function_pod.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
from orcapod.protocols.database_protocols import ArrowDatabaseProtocol
from orcapod.protocols.observability_protocols import DataExecutionLoggerProtocol

from orcapod.semantic_types._schema_conversion import arrow_schema_for_types

if TYPE_CHECKING:
import pyarrow as pa

Expand Down Expand Up @@ -116,8 +118,8 @@ def require_storable_results(self) -> None:
},
**pf.output_data_schema,
}
declared = self.data_context.type_converter.python_schema_to_arrow_schema(
python_schema
declared = arrow_schema_for_types(
self.data_context.type_converter, python_schema
)
schema = pa.schema(
[
Expand Down Expand Up @@ -246,11 +248,13 @@ def process_data(
var_dg = Datagram(
pf.get_function_variation_data(),
python_schema=pf.get_function_variation_data_schema(),
_inherited_schema=True,
data_context=pf.data_context,
)
exec_dg = Datagram(
pf.get_execution_data(),
python_schema=pf.get_execution_data_schema(),
_inherited_schema=True,
data_context=pf.data_context,
)
# Write if missing (ITL-1503): a result stored for this input since the
Expand Down Expand Up @@ -315,11 +319,13 @@ async def _async_compute_and_store(
var_dg = Datagram(
pf.get_function_variation_data(),
python_schema=pf.get_function_variation_data_schema(),
_inherited_schema=True,
data_context=pf.data_context,
)
exec_dg = Datagram(
pf.get_execution_data(),
python_schema=pf.get_execution_data_schema(),
_inherited_schema=True,
data_context=pf.data_context,
)
# Write if missing (ITL-1503): a result stored for this input since the
Expand Down
30 changes: 26 additions & 4 deletions src/orcapod/core/data_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@

from orcapod.protocols.observability_protocols import DataExecutionLoggerProtocol

from orcapod.semantic_types.narrow_float_keys import (
require_python_schema_without_narrow_float_keys,
)
from orcapod.semantic_types._schema_conversion import arrow_table_for_rows

if TYPE_CHECKING:
from orcapod.logical_types.protocols import (
TypeConverterProtocol as LogicalTypeConverterProtocol,
Expand Down Expand Up @@ -836,6 +841,8 @@ def __init__(
data_context: str | DataContext | None = None,
config: OrcapodConfig | None = None,
executor: PythonFunctionExecutorProtocol | None = None,
*,
_ctx_arg_name: str | None = None,
) -> None:

# default to the basic PythonFunctionExecutor
Expand Down Expand Up @@ -920,6 +927,15 @@ def __init__(
output_typespec=output_schema,
)

declared_inputs = {
name: annotation
for name, annotation in self._input_schema.items()
if name != _ctx_arg_name
}
require_python_schema_without_narrow_float_keys(
declared_inputs, self.data_context.type_converter, self._output_schema
)

# get git info for the function
# TODO: turn this into optional addition
env_info = get_git_info_for_python_object(self._function, try_cwd=True)
Expand Down Expand Up @@ -1112,6 +1128,7 @@ def _build_output_data(self, values: Any) -> DataProtocol:
source_info=source_info,
record_uuid=new_record_uuid,
python_schema=output_schema,
_inherited_schema=True,
data_context=self.data_context,
)
# Validate storage eagerly, but retain compatible user-class instances. Reading
Expand All @@ -1126,6 +1143,7 @@ def _build_output_data(self, values: Any) -> DataProtocol:
return Data(
normalized,
python_schema=output_schema,
_inherited_schema=True,
source_info=source_info,
record_uuid=new_record_uuid,
data_context=self.data_context,
Expand Down Expand Up @@ -1169,15 +1187,17 @@ def _convert_outputs(
"""
converter = self.data_context.type_converter
try:
return converter.python_dicts_to_arrow_table(
[output_data], python_schema=output_schema
return arrow_table_for_rows(
converter, [output_data], python_schema=output_schema
)
except Exception as exc:
# Find the output that fails on its own, so the error can name it.
for key, value in output_data.items():
try:
_ = converter.python_dicts_to_arrow_table(
[{key: value}], python_schema={key: output_schema[key]}
_ = arrow_table_for_rows(
converter,
[{key: value}],
python_schema={key: output_schema[key]},
)
except UnstorableDatetimeError as failure:
# The datetime rule says what is wrong and how to convert,
Expand Down Expand Up @@ -1633,11 +1653,13 @@ def _build_metadata_datagrams(self) -> tuple[Datagram, Datagram]:
variation_datagram = Datagram(
self.get_function_variation_data(),
python_schema=self.get_function_variation_data_schema(),
_inherited_schema=True,
data_context=self.data_context,
)
execution_datagram = Datagram(
self.get_execution_data(),
python_schema=self.get_execution_data_schema(),
_inherited_schema=True,
data_context=self.data_context,
)
return variation_datagram, execution_datagram
Expand Down
Loading
Loading