Skip to content

Commit

Permalink
Fix the callable's method not found issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jmao-denver committed Mar 9, 2023
1 parent f642bb4 commit 7ddbc61
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private Method getMethod(final Class<?> scope, final String methodName, final Cl
}
}
} else {
if (scope == org.jpy.PyObject.class) {
if (scope == org.jpy.PyObject.class || scope == PyCallableWrapper.class) {
// This is a Python method call, assume it exists and wrap in PythonScopeJpyImpl.CallableWrapper
for (Method method : PyCallableWrapper.class.getDeclaredMethods()) {
possiblyAddExecutable(acceptableMethods, method, "call", paramTypes, parameterizedTypes);
Expand Down
18 changes: 13 additions & 5 deletions py/server/tests/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,7 +903,7 @@ def make_pairs_3(tid, a, b):
self.assertEqual(x2.size, 10)
self.assertEqual(x3.size, 10)

def test_class_attrs_in_query(self):
def test_callable_attrs_in_query(self):
input_cols = [
datetime_col(name="DTCol", data=[dtypes.DateTime(1), dtypes.DateTime(10000000)]),
]
Expand All @@ -913,13 +913,16 @@ def test_class_attrs_in_query(self):
self.assertEqual(rt.size, test_table.size)

class Foo:
ATTR = 1
ATTR = 256

def __ceil__(self):
def __call__(self):
...

def do_something(self):
return 1
def do_something(self, p=None):
return p if p else 1

def do_something(p=None):
return p if p else 1

rt = empty_table(1).update("Col = Foo.ATTR")
self.assertTrue(rt.columns[0].data_type == dtypes.PyObject)
Expand All @@ -931,6 +934,11 @@ def do_something(self):
rt = empty_table(1).update("Col = (int)foo.do_something()")
self.assertTrue(rt.columns[0].data_type == dtypes.int32)

rt = empty_table(1).update("Col = (int)do_something((byte)Foo.ATTR)")
df = to_pandas(rt)
self.assertEqual(df.loc[0]['Col'], 1)
self.assertTrue(rt.columns[0].data_type == dtypes.int32)


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

0 comments on commit 7ddbc61

Please sign in to comment.