Skip to content

converter: cast ints to float in float-inferred fields before table build - #132

Merged
jghoman merged 1 commit into
mainfrom
jakob/floatify-large-ints
Sep 2, 2026
Merged

jghoman merged 1 commit into
mainfrom
jakob/floatify-large-ints

Conversation

@jghoman

@jghoman jghoman commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Problem

session-replay-features crash-loops: the topic's float aggregates JSON-serialize as integers when whole, and one record carried 130184854372975800 (> 2^53) in a double-inferred field. pa.Table.from_pylist refuses inexact int→double, so the batch crashes inside convert()before coerce_typed_columns runs, which is why the typedColumns pins (PostHog/charts#15010) can't fix this half of the failure.

Fix

_floatify_integers_in_float_fields: after schema inference and mixed-type stringification, cast int values to float() for fields the schema types as floating. Nearest-double is the intended semantics for floating measures; PyArrow's exactness check is the only obstacle. Int-only fields are untouched (schema infers int64, no cast) — the existing test_large_integer_precision_preserved guarding >2^53 int precision still passes.

Records are only copied when a cast is needed; the common all-float path allocates nothing.

Tests

  • New: test_large_int_in_float_field_converts_lossily (the exact prod poison value) and test_whole_int_in_float_field_stays_float.
  • Full unit suite: 796 passed. ruff check/format clean.

Deploy

Standard release path: merge → release workflow → Promote-to-prod retag. The session consumers are scaled to zero pending this + the charts pins; re-enable follows both.

…uild

JSON producers emit whole floats as integers. PyArrow accepts an int in
a double column only when the conversion is exact; an integer above 2^53
makes pa.Table.from_pylist raise ArrowInvalid and the batch crashes
before any column coercion runs (session_replay_features carried
130184854372975800 in a mouse aggregate and crash-looped the consumer).

Pre-cast ints to float when the inferred field type is floating -
nearest-double is the wanted semantics for a floating measure. Int-only
fields are untouched and keep exact int64 (existing large-int precision
test still passes).
@jghoman
jghoman merged commit 8d7e12d into main Sep 2, 2026
17 checks passed
@jghoman
jghoman deleted the jakob/floatify-large-ints branch September 2, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant