From 8b892aa89ceace05147eff1d69205fbe28310a50 Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Tue, 19 Nov 2024 10:09:29 -0700 Subject: [PATCH 1/2] Fix a bug when py callable has no __name__ attr --- .../io/deephaven/engine/util/PyCallableWrapperJpyImpl.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/engine/table/src/main/java/io/deephaven/engine/util/PyCallableWrapperJpyImpl.java b/engine/table/src/main/java/io/deephaven/engine/util/PyCallableWrapperJpyImpl.java index bfb061c5e7a..df25e5ba29e 100644 --- a/engine/table/src/main/java/io/deephaven/engine/util/PyCallableWrapperJpyImpl.java +++ b/engine/table/src/main/java/io/deephaven/engine/util/PyCallableWrapperJpyImpl.java @@ -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 parameters = signature.getParameters(); if (parameters.size() == 0 && argTypes.length > 0) { From 454111b569dba6ffa7e5f8b288280a29453e644c Mon Sep 17 00:00:00 2001 From: jianfengmao Date: Tue, 19 Nov 2024 10:55:55 -0700 Subject: [PATCH 2/2] Add a test case --- py/server/tests/test_udf_scalar_args.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/py/server/tests/test_udf_scalar_args.py b/py/server/tests/test_udf_scalar_args.py index 617fa85be86..8f360a364e8 100644 --- a/py/server/tests/test_udf_scalar_args.py +++ b/py/server/tests/test_udf_scalar_args.py @@ -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()