Skip to content

Commit af337c3

Browse files
committed
Add test and typing for python functions as strings
1 parent 8716baf commit af337c3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

servicex/python_dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, dataset_identifier: DID,
5959

6060
self.python_function = None
6161

62-
def with_uproot_function(self, f: typing.Callable) -> Dataset:
62+
def with_uproot_function(self, f: typing.Union[str, typing.Callable]) -> Dataset:
6363
self.python_function = f
6464
return self
6565

tests/test_python_dataset.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,21 @@ def run_query(input_filenames=None):
5959
print(selection)
6060
print("==============")
6161
print(b64decode(selection))
62+
63+
64+
def test_function_as_string():
65+
did = FileListDataset("/foo/bar/baz.root")
66+
datasource = PythonDataset(dataset_identifier=did,
67+
codegen="uproot",
68+
sx_adapter=None,
69+
query_cache=None)
70+
71+
string_function = """
72+
def run_query(input_filenames=None):
73+
print("Greetings from your query")
74+
return []
75+
"""
76+
selection = datasource.with_uproot_function(string_function).generate_selection_string()
77+
print(selection)
78+
print("==============")
79+
print(b64decode(selection))

0 commit comments

Comments
 (0)