fix: add float support to merge_dicts and merge_obj#36048
fix: add float support to merge_dicts and merge_obj#36048RoomWithOutRoof (Jah-yee) wants to merge 1 commit intolangchain-ai:masterfrom
Conversation
- Changed isinstance(merged[right_k], int) to isinstance(merged[right_k], (int, float)) - Added numeric type handling in merge_obj for int and float - Fixes issue langchain-ai#36011: merge_dicts raises TypeError for float values during streaming chunk aggregation
Merging this PR will not alter performance
|
|
This PR has been automatically closed because it does not link to an approved issue. All external contributions must reference an approved issue or discussion. Please:
|
Summary
Fixes issue #36011:
merge_dictsraisesTypeErrorfor float values during streaming chunk aggregation.Changes
merge_dicts(): Changedisinstance(merged[right_k], int)toisinstance(merged[right_k], (int, float))to handle float values the same way as integers.merge_obj(): Added numeric type handling forintandfloat- now sums numeric values (consistent withmerge_dictsbehavior).Root Cause
The function handled
str,dict,list, equal values, andinttypes — but notfloat. When two dicts contain the same key with unequalfloatvalues (e.g.,logprob,score, safety scores, cost fields in streaming), the function falls through to the finalelsebranch and raises aTypeError.Testing
This fix enables the following to work without errors:
Related
merge_dictsraises TypeError for float values during streaming chunk aggregation #36011