Skip to content

Commit

Permalink
Merge pull request #932 from parea-ai/safe-serialize-obj
Browse files Browse the repository at this point in the history
safe serialize obj
  • Loading branch information
jalexanderII authored Jun 13, 2024
2 parents 701ffba + 6c106c6 commit 0769b4b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions parea/utils/universal_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,19 @@ def default(self, obj: Any):
return str(obj)
elif isinstance(obj, Decimal):
return float(obj)
elif callable(obj):
return f"<callable {obj.__name__}>"
elif isinstance(obj, bytes):
return obj.decode(errors="ignore")
elif is_numpy_instance(obj):
return obj.tolist()
elif is_pandas_instance(obj):
return obj.to_dict(orient="records")
elif dspy_response := self.handle_dspy_response(obj):
return dspy_response
elif callable(obj):
try:
return f"<callable {obj.__name__}>"
except AttributeError:
return str(obj)
elif isinstance(obj, bytes):
return obj.decode(errors="ignore")
else:
return super().default(obj)

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "poetry.core.masonry.api"
[tool.poetry]
name = "parea-ai"
packages = [{ include = "parea" }]
version = "0.2.173"
version = "0.2.174"
description = "Parea python sdk"
readme = "README.md"
authors = ["joel-parea-ai <[email protected]>"]
Expand Down

0 comments on commit 0769b4b

Please sign in to comment.