Skip to content

Commit dd8b252

Browse files
Benjamin Gutzmanngutzbenj
authored andcommitted
Fix format_threshold to cast infinity values in query
1 parent ef97931 commit dd8b252

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Types of changes:
2020

2121
- Fix query wrapping
2222
- Fix date column type casting in SQL queries to handle TIMESTAMP values correctly
23+
- Fix format_threshold to cast infinity values in query
2324

2425
## [0.6.0] - 2026-01-07
2526

src/koality/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ def load_to_database(self) -> None:
425425
'{row[identifier_column]}',
426426
{f"'{row['COLUMN']}'" if row["COLUMN"] is not None else "NULL"},
427427
{row["VALUE"] if row["VALUE"] is not None else "NULL"},
428-
{format_threshold(row["LOWER_THRESHOLD"])},
429-
{format_threshold(row["UPPER_THRESHOLD"])},
428+
{format_threshold(row["LOWER_THRESHOLD"]).format(numeric_type=DATA_TYPES["NUMERIC"][self.database_provider.type])},
429+
{format_threshold(row["UPPER_THRESHOLD"]).format(numeric_type=DATA_TYPES["NUMERIC"][self.database_provider.type])},
430430
'{row["RESULT"]}',
431431
'{row["INSERT_TIMESTAMP"]}'
432432
)

src/koality/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,6 @@ def format_threshold(value: float | None) -> str:
199199
return "NULL"
200200
if math.isinf(value):
201201
if value > 0:
202-
return "'+Infinity'"
203-
return "'-Infinity'"
202+
return "CAST('+Infinity' AS {numeric_type})"
203+
return "CAST('-Infinity' AS {numeric_type})"
204204
return str(value)

tests/unit/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,8 @@ def test_special_characters_in_value(self) -> None:
150150
("value", "expected"),
151151
[
152152
(None, "NULL"),
153-
(float("inf"), "'+Infinity'"),
154-
(float("-inf"), "'-Infinity'"),
153+
(float("inf"), "CAST('+Infinity' AS {numeric_type})"),
154+
(float("-inf"), "CAST('-Infinity' AS {numeric_type})"),
155155
(0.0, "0.0"),
156156
(42.5, "42.5"),
157157
(-10.25, "-10.25"),

0 commit comments

Comments
 (0)