* feat: Implement serialization functions for various data types and add a unified serialize method * optmize conditional Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com> * fix: Update string and list truncation to include ellipsis for clarity * ⚡️ Speed up function `_serialize_series` by 234% in PR #6044 (`refactor-serialization`) Certainly! Here is a more optimized version of the program. Changes made. 1. Replaced the `apply` method with dictionary comprehension. This avoids creating an intermediate Series, which can be an expensive operation. 2. Moved `_truncate_value` outside of the main function to keep the main function concise and focused. * refactor: Remove unused `_truncate_value` function from serialization module --------- Co-authored-by: Gabriel Luiz Freitas Almeida <gabriel@langflow.org> Co-authored-by: codeflash-ai[bot] <148906541+codeflash-ai[bot]@users.noreply.github.com>
This commit is contained in:
parent
5ef9d34599
commit
4fd2b2feb1
1 changed files with 1 additions and 2 deletions
|
|
@ -128,8 +128,7 @@ def _serialize_series(obj: pd.Series, max_length: int | None, max_items: int | N
|
|||
"""Serialize pandas Series to a dictionary format."""
|
||||
if max_items is not None and len(obj) > max_items:
|
||||
obj = obj.head(max_items)
|
||||
obj = obj.apply(lambda x: _truncate_value(x, max_length, max_items))
|
||||
return obj.to_dict()
|
||||
return {index: _truncate_value(value, max_length, max_items) for index, value in obj.items()}
|
||||
|
||||
|
||||
def _is_numpy_type(obj: Any) -> bool:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue