Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(data-imports): coerce numeric-string cells in numeric columns (#73286)

Tom Owers18564483cf0c
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py
index b7d6e0df64b0..75202a084caa 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/test/test_pipeline_utils.py
@@ -92,6 +92,24 @@ def test_table_from_py_list_numeric_column_with_non_numeric_value_raises_named_e
assert "<blank>" in message
+def test_table_from_py_list_numeric_column_coerces_numeric_string_values():
+ # Numeric columns whose cells arrive as numeric strings (common with JSON-based sources
+ # such as Mixpanel, where a property flips between 570 and "570") must coerce, not fail
+ # the whole sync. Blank cells become null; genuinely non-numeric text still raises.
+ table = table_from_py_list(
+ [{"column": 1.5}, {"column": "570"}, {"column": " 42 "}, {"column": ""}, {"column": None}]
+ )
+
+ assert pa.types.is_decimal(table.schema.field("column").type)
+ assert table.column("column").to_pylist() == [
+ decimal.Decimal("1.5"),
+ decimal.Decimal("570"),
+ decimal.Decimal("42"),
+ None,
+ None,
+ ]
+
+
@pytest.mark.parametrize(
"values,expected,type_check",
[
diff --git a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py
index 7c95fbcd7cef..93cfee3b5a7c 100644
--- a/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py
+++ b/products/warehouse_sources/backend/temporal/data_imports/pipelines/pipeline/utils.py
@@ -1183,8 +1183,14 @@ def _process_batch(table_data: list[dict], schema: Optional[pa.Schema] = None) -
return None
if isinstance(x, str):
- # Non-numeric value in a column imported as a number; the caller adds column context.
- raise TypeError("must be real number, not str")
+ stripped = x.strip()
+ if stripped == "":
+ return None
+ try:
+ x = decimal.Decimal(stripped)
+ except decimal.InvalidOperation:
+ # A genuinely non-numeric value in a column imported as a number; the caller adds column context.
+ raise TypeError("must be real number, not str")
if (
math.isnan(x)
@@ -1203,7 +1209,13 @@ def _process_batch(table_data: list[dict], schema: Optional[pa.Schema] = None) -
return None
if isinstance(x, str):
- raise TypeError("must be real number, not str")
+ stripped = x.strip()
+ if stripped == "":
+ return None
+ try:
+ x = float(stripped)
+ except ValueError:
+ raise TypeError("must be real number, not str")
if math.isnan(x) or np.isinf(x):
return None