Skip to content

fix(serializer): NaN to string rather than None #1253

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged

fix(serializer): NaN to string rather than None #1253

merged 1 commit into from
Jul 14, 2025

Conversation

hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jul 14, 2025

Disclaimer: Experimental PR review

Greptile Summary

This PR addresses how the langfuse Python SDK handles NaN (Not a Number) values during JSON serialization. The change modifies the EventSerializer class to serialize NaN values as the string "NaN" instead of None. This is a small but important change that improves consistency in how numerical edge cases are handled, particularly aligning with JavaScript's JSON handling and matching the existing behavior for infinity values in the codebase.

The change is implemented by adding a specific check for NaN float values using math.isnan() and returning the string "NaN" instead of the previous implicit None conversion. This modification helps maintain semantic clarity since None and NaN have distinct meanings in programming contexts.

Confidence score: 4/5

  1. This PR is safe to merge as it's a focused change improving data serialization consistency
  2. High confidence due to the small scope, clear purpose, and alignment with established serialization patterns
  3. Files needing attention:
    • langfuse/_utils/serializer.py - verify this doesn't break any existing consumers expecting None values

1 file reviewed, no comments
Edit PR Review Bot Settings | Greptile


Important

Change serialization of NaN values from None to "NaN" in default() method of EventSerializer.

  • Behavior:
    • Change serialization of NaN values from None to "NaN" in default() method of EventSerializer in serializer.py.

This description was created by Ellipsis for 4c533e0. You can customize this summary. It will automatically update as commits are pushed.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewing changes made in this pull request

@hassiebp hassiebp merged commit b0121c0 into main Jul 14, 2025
8 of 10 checks passed
@hassiebp hassiebp deleted the fix-nan branch July 14, 2025 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant