Skip to content

Conversation

@marcklingen
Copy link
Member

@marcklingen marcklingen commented Jul 7, 2025

Add serialization for NumPy ndarray objects to allow them in span input/output.

This implements the simple list conversion approach, transforming np.ndarray instances into standard Python lists for JSON serialization.


Important

Adds support for serializing NumPy arrays in EventSerializer by converting them to lists, with tests for various array types.

  • Behavior:
    • Adds support for serializing np.ndarray objects in EventSerializer by converting them to lists.
    • Handles 1D, 2D, float, empty, and mixed-type arrays.
  • Tests:
    • Adds test_numpy_arrays() in test_serializer.py to verify serialization of various np.ndarray types.

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

Greptile Summary

Disclaimer: Experimental PR review

Added NumPy array serialization support to langfuse/_utils/serializer.py, enabling ndarray objects to be used in span input/output by converting them to Python lists.

  • Added ndarray serialization to EventSerializer using tolist() method for JSON compatibility
  • Added comprehensive test coverage in tests/test_serializer.py for various array types (1D, 2D, float, empty, mixed)
  • Builds on existing NumPy support that was already handling float32 types
  • Implementation follows established pattern for handling numpy.generic types

Co-authored-by: marc <marc@langfuse.com>
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.

LGTM

2 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@marcklingen marcklingen requested a review from hassiebp July 7, 2025 18:48
@marcklingen marcklingen changed the title Add numpy serialization function feat: add serialization of numpy ndarray Jul 7, 2025
@hassiebp hassiebp merged commit acfc5a0 into main Jul 8, 2025
7 checks passed
@hassiebp hassiebp deleted the cursor/add-numpy-serialization-function-4cf5 branch July 8, 2025 11:24
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.

4 participants