Skip to content

Commit

Permalink
fix: Use the string representation of a Python UDF as its name when i…
Browse files Browse the repository at this point in the history
…t doesn't have the __name__ attribute (#6399)

Fixes #6397
  • Loading branch information
jmao-denver authored Nov 19, 2024
1 parent e096c1f commit 2b6bd3c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,12 @@ public void verifyArguments(Class<?>[] argTypes) {
return;
}

String callableName = pyCallable.getAttribute("__name__").toString();
String callableName;
if (pyCallable.hasAttribute("__name__")) {
callableName = pyCallable.getAttribute("__name__").toString();
} else {
callableName = pyCallable.toString();
}
List<Parameter> parameters = signature.getParameters();

if (parameters.size() == 0 && argTypes.length > 0) {
Expand Down
11 changes: 11 additions & 0 deletions py/server/tests/test_udf_scalar_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,17 @@ def test_no_signature(self):
self.assertEqual(t.columns[0].data_type, dtypes.int32)
self.assertEqual(10, t.to_string().count("3"))

def test_no_name(self):
from functools import partial
def fn(i: int, z: int) -> int:
return i * 5 - z
local_fn = partial(fn, z=5)

t = empty_table(5).update("col=i*2")
t = t.update('col2=local_fn(col)')
self.assertEqual(t.columns[1].data_type, dtypes.int64)
self.assertEqual(5, t.size)


if __name__ == "__main__":
unittest.main()

0 comments on commit 2b6bd3c

Please sign in to comment.