Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix flakey print_code test

Shahmir Varqha1f706a225b8a
diff --git a/tests/_plugins/ui/_impl/dataframes/test_print_code.py b/tests/_plugins/ui/_impl/dataframes/test_print_code.py
index ea3af473f3..2275a683de 100644
--- a/tests/_plugins/ui/_impl/dataframes/test_print_code.py
+++ b/tests/_plugins/ui/_impl/dataframes/test_print_code.py
@@ -587,6 +587,18 @@ def test_print_code_result_matches_actual_transform_polars(
"mean",
}:
assume(False)
+ # Polars does not support sum/mean/median on string or other non-numeric columns
+ if transform.aggregation in {"sum", "mean", "median"}:
+ if not transform.aggregation_column_ids:
+ assume(False) # all columns used; would include strings
+ else:
+ numeric_only = {"integers", "floats", "mixed"}
+ assume(
+ all(
+ col in numeric_only
+ for col in transform.aggregation_column_ids
+ )
+ )
if transform.type == TransformType.PIVOT:
assume(
(
@@ -636,6 +648,18 @@ def test_print_code_result_matches_actual_transform_polars(
"mean",
}:
assume(False)
+ # Polars does not support sum/mean on string or other non-numeric columns
+ if (
+ transform.aggregation in {"sum", "mean"}
+ and transform.value_column_ids
+ ):
+ numeric_only = {"integers", "floats", "mixed"}
+ assume(
+ not any(
+ col not in numeric_only
+ for col in transform.value_column_ids
+ )
+ )
# Polars
polars_code = python_print_transforms(