Skip to content
Open
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
5 changes: 4 additions & 1 deletion src/bioetl/domain/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,11 @@ def is_complex_type(field_type: pa.DataType) -> bool:

def serialize_column_to_json(col: pa.ChunkedArray) -> pa.Array:
"""Serialize a complex Arrow column into stringified JSON values."""
# Performance optimization: .as_py() is expensive for PyArrow scalars.
# Use the walrus operator to evaluate it once per element instead of twice.
vals = [
serialize_to_json(v.as_py()) if v.as_py() is not None else None for v in col
serialize_to_json(val) if (val := v.as_py()) is not None else None
for v in col
]
return pa.array(vals, type=pa.string())

Expand Down
Loading