Skip to content

Commit e20ec7a

Browse files
committed
fix python nan and inf resolution
1 parent 87dcd53 commit e20ec7a

File tree

1 file changed

+9
-1
lines changed
  • apps/sim/app/api/function/execute

1 file changed

+9
-1
lines changed

apps/sim/app/api/function/execute/route.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,15 @@ export async function POST(req: NextRequest) {
778778
} else if (typeof v === 'boolean') {
779779
prologue += `${k} = ${v ? 'True' : 'False'}\n`
780780
} else if (typeof v === 'number') {
781-
prologue += `${k} = ${v}\n`
781+
if (Number.isNaN(v)) {
782+
prologue += `${k} = float('nan')\n`
783+
} else if (v === Number.POSITIVE_INFINITY) {
784+
prologue += `${k} = float('inf')\n`
785+
} else if (v === Number.NEGATIVE_INFINITY) {
786+
prologue += `${k} = float('-inf')\n`
787+
} else {
788+
prologue += `${k} = ${v}\n`
789+
}
782790
} else {
783791
prologue += `${k} = json.loads(${JSON.stringify(JSON.stringify(v))})\n`
784792
}

0 commit comments

Comments
 (0)