From 5f74ad1a515f7747a2c4a1cce8b8c84aff76da49 Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Sun, 29 Nov 2026 16:55:27 -0800 Subject: [PATCH 1/2] test(semantic-types): stabilize Arrow fixture identities across Python versions --- changelog.d/ITL-1591.md | 2 ++ .../test_narrow_float_arrow_compatibility.py | 24 +++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/changelog.d/ITL-1591.md b/changelog.d/ITL-1591.md index d0f798265..77d98cdc8 100644 --- a/changelog.d/ITL-1591.md +++ b/changelog.d/ITL-1591.md @@ -6,6 +6,8 @@ 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. +- The Arrow source compatibility tests use the same synthetic class identities + across supported Python versions. ### Known limitations diff --git a/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py b/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py index f4407c939..5c1a08928 100644 --- a/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py +++ b/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py @@ -101,6 +101,15 @@ def _ipc_storage_round_trip(table: pa.Table) -> pa.Table: return pa.ipc.open_file(buffer.getvalue()).read_all() +def _snapshot_dataclass(name: str, fields: list[tuple[str, Any]]) -> type: + """Create a class with the module name embedded in the main snapshot.""" + cls = make_dataclass(name, fields) + # make_dataclass handles namespace["__module__"] differently on 3.11 and + # newer Python versions. Set the identity explicitly after construction. + cls.__module__ = "tests.test_semantic_types.test_narrow_float_arrow_compatibility" + return cls + + def _arrow_input(case: str) -> tuple[pa.Table, contexts.DataContext]: context = _context() if case.startswith("custom"): @@ -128,14 +137,11 @@ def _arrow_input(case: str) -> tuple[pa.Table, contexts.DataContext]: # The writer owns the original class registrations. The reader either # registers an incompatible class of the same name or has neither class. writer = _context().type_converter - namespace = {"__module__": "itl1591_arrow_compatibility"} if case == "newer-class": - original = make_dataclass( - "Entries", [("entries", dict[str, int])], namespace=namespace - ) + original = _snapshot_dataclass("Entries", [("entries", dict[str, int])]) item = original(entries={"string": 4}) - replacement = make_dataclass( - "Entries", [("entries", dict[np.float32, int])], namespace=namespace + replacement = _snapshot_dataclass( + "Entries", [("entries", dict[np.float32, int])] ) assert (replacement.__module__, replacement.__qualname__) == ( original.__module__, @@ -149,10 +155,8 @@ def _arrow_input(case: str) -> tuple[pa.Table, contexts.DataContext]: set[np.float32] if case.endswith("set") else dict[np.float32, int] ) value = {np.float32(0.5)} if case.endswith("set") else {np.float32(0.5): 4} - inner = make_dataclass( - "Inner", [("entries", annotation)], namespace=namespace - ) - outer = make_dataclass("Outer", [("nested", inner)], namespace=namespace) + inner = _snapshot_dataclass("Inner", [("entries", annotation)]) + outer = _snapshot_dataclass("Outer", [("nested", inner)]) item = outer(nested=inner(entries=value)) table = writer.python_dicts_to_arrow_table([{"id": 1, "k": item}]) return _ipc_storage_round_trip(table), context From 9fa8931fbd889d03ff9ce3b9d2b209dcad7f315a Mon Sep 17 00:00:00 2001 From: "Edgar Y. Walker" Date: Sun, 29 Nov 2026 16:56:57 -0800 Subject: [PATCH 2/2] test(semantic-types): type the fixture fields without Any --- .../test_narrow_float_arrow_compatibility.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py b/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py index 5c1a08928..91fdb3e02 100644 --- a/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py +++ b/tests/test_semantic_types/test_narrow_float_arrow_compatibility.py @@ -101,7 +101,7 @@ def _ipc_storage_round_trip(table: pa.Table) -> pa.Table: return pa.ipc.open_file(buffer.getvalue()).read_all() -def _snapshot_dataclass(name: str, fields: list[tuple[str, Any]]) -> type: +def _snapshot_dataclass(name: str, fields: list[tuple[str, object]]) -> type: """Create a class with the module name embedded in the main snapshot.""" cls = make_dataclass(name, fields) # make_dataclass handles namespace["__module__"] differently on 3.11 and