Skip to content

Commit 6f4b6c2

Browse files
committed
fix: resolve type coercion issue in sum_results function
- Add dynamic default value calculation based on inferred types - Use 0.0 for floats and 0 for integers to avoid type coercion - Prevents downstream issues caused by incorrect type handling
1 parent 1b7cee1 commit 6f4b6c2

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Fixed
1919

20-
*
20+
* Type coercion issue in `sum_results` by using dynamic default values based on inferred types
2121

2222
## [0.3.10] - 2026-01-11
2323

src/omnix/util/business.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,18 @@ def sum_results(first, second, calc=True):
839839
result_r[key] = result_m
840840

841841
# iterates over the complete set of keys in the first
842-
# map to calculate the complete set of sums
842+
# map to calculate the complete set of sums, notice that
843+
# the default value is dynamically calculated from the
844+
# inferred type of the values, this avoid coercion of types
845+
# which would cause issues downstream
843846
for _key in quorum.legacy.iterkeys(first_m):
844-
result_m[_key] = first_m.get(_key, 0.0) + second_m.get(_key, 0.0)
847+
first, second = first_m.get(_key, None), second_m.get(_key, None)
848+
default_v = (
849+
0.0 if isinstance(first, float) or isinstance(second, float) else 0
850+
)
851+
result_m[_key] = first_m.get(_key, default_v) + second_m.get(
852+
_key, default_v
853+
)
845854

846855
if calc:
847856
calc_extra(result)

0 commit comments

Comments
 (0)