Skip to content

Commit

Permalink
update semantics for returning dicts (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
diptanu authored Dec 28, 2024
1 parent 53939d9 commit c85193d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
4 changes: 4 additions & 0 deletions python-sdk/indexify/functions_sdk/indexify_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ def run_router(
# with json encoding which won't deserialize in tuple.
if isinstance(input, tuple) or isinstance(input, list):
args += input
elif isinstance(input, dict):
kwargs.update(input)
else:
args.append(input)
extracted_data = self.indexify_function._call_run(*args, **kwargs)
Expand All @@ -292,6 +294,8 @@ def run_fn(
# with json encoding which won't deserialize in tuple.
if isinstance(input, tuple) or isinstance(input, list):
args += input
elif isinstance(input, dict):
kwargs.update(input)
else:
args.append(input)

Expand Down
2 changes: 1 addition & 1 deletion python-sdk/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "indexify"
version = "0.2.46"
version = "0.2.47"
description = "Python Client for Indexify"
authors = ["Tensorlake Inc. <[email protected]>"]
license = "Apache 2.0"
Expand Down
14 changes: 7 additions & 7 deletions python-sdk/tests/test_graph_behaviours.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def my_router(x: int, y: int, z: int) -> List[Union[my_func_2, my_func_3]]:
def test_return_dict_as_args(self, is_remote):
@indexify_function()
def my_func(x: int) -> dict:
return dict(x=1, y=2, z=3)
return {"input": dict(x=1, y=2, z=3)}

@indexify_function()
def my_func_2(input: dict) -> int:
Expand All @@ -444,7 +444,7 @@ def my_func_2(input: dict) -> int:
def test_return_multiple_dict_as_args(self, is_remote):
@indexify_function()
def my_func(x: int) -> dict:
return dict(x=1, y=2, z=3), dict(x=1, y=2, z=3)
return {"input1": dict(x=1, y=2, z=3), "input2": dict(x=1, y=2, z=3)}

@indexify_function()
def my_func_2(input1: dict, input2: dict) -> int:
Expand Down Expand Up @@ -516,8 +516,8 @@ def my_func_2(x: int, y: int, z: int) -> int:
@parameterized.expand([(False), (True)])
def test_return_dict_args_json(self, is_remote):
@indexify_function(input_encoder="json", output_encoder="json")
def my_func(x: int) -> tuple:
return dict(x=1, y=2, z=3)
def my_func(x: int) -> dict:
return {"input": dict(x=1, y=2, z=3)}

@indexify_function(input_encoder="json", output_encoder="json")
def my_func_2(input: dict) -> int:
Expand All @@ -537,7 +537,7 @@ def my_func_2(input: dict) -> int:

output1 = graph.output(invocation_id, my_func.name)
self.assertEqual(len(output1), 1)
self.assertEqual(output1[0], {"x": 1, "y": 2, "z": 3})
self.assertEqual(output1[0], {"input": {"x": 1, "y": 2, "z": 3}})

@parameterized.expand([(False), (True)])
def test_return_dict_args_as_kwargs_in_list(self, is_remote):
Expand Down Expand Up @@ -567,7 +567,7 @@ def my_func_2(index: int, char: str) -> str:
def test_return_dict_args_as_dict_in_list(self, is_remote):
@indexify_function()
def my_func(text: str) -> List[dict]:
return [dict(index=index, char=char) for index, char in enumerate(text)]
return [{"data": {"index":index, "char":char}} for index, char in enumerate(text)]

@indexify_function()
def my_func_2(data: dict) -> str:
Expand Down Expand Up @@ -807,7 +807,7 @@ class P1(BaseModel):

@indexify_function(input_encoder="json", output_encoder="json")
def my_func1(x: int) -> dict:
return P1(a=x).model_dump()
return {"input": P1(a=x).model_dump()}

@indexify_function(input_encoder="json", output_encoder="json")
def my_func_2(input: dict) -> int:
Expand Down

0 comments on commit c85193d

Please sign in to comment.