You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to wrap a python code from a colleague. I would like to avoid any changes to the python code that makes the python code less general. I have a problem when the code uses ellipses (...) as indices on numpy array:
Is your feature request related to a problem? Please describe.
Consider the python code (in file test_ellipsis.py) :
deftest_ellipsis(X):
print("sum", X[0,...].sum())
The code is called in julia as:
using PythonCall
pyimport("sys").path.append("/add/file/path/to/python/script/")
pyimport("test_ellipsis").test_ellipsis(randn(2,2,2))
Wrapped Julia arrays intentionally only support some very basic behaviour. If you want more array functionality you should convert it to a specialised array type like a numpy array.
Your test_ellipsis(X) function implicitly assumes that X is a numpy array, so you should pass one, like your suggested work-around.
Alternatively the function could be modified to take more general array-like types by converting X itself to a numpy array, but you said that you cannot change the python code.
Your specific suggestion of supporting ... wouldn't even help because it would then error on .sum() which also isn't implemented for wrapped Julia arrays.
Ok, Thank you for clarifying that. Actually, in my case, all python functions that I try to wrap essentially assume that arguments are numpy arrays. Is there a way to make the conversation automatic? Or would it be necessary to wrap the arguments manually?
Activity
cjdoris commentedon Sep 24, 2026
Wrapped Julia arrays intentionally only support some very basic behaviour. If you want more array functionality you should convert it to a specialised array type like a numpy array.
Your
test_ellipsis(X)function implicitly assumes thatXis a numpy array, so you should pass one, like your suggested work-around.Alternatively the function could be modified to take more general array-like types by converting
Xitself to a numpy array, but you said that you cannot change the python code.Your specific suggestion of supporting
...wouldn't even help because it would then error on.sum()which also isn't implemented for wrapped Julia arrays.Alexander-Barth commentedon Sep 28, 2026
Ok, Thank you for clarifying that. Actually, in my case, all python functions that I try to wrap essentially assume that arguments are numpy arrays. Is there a way to make the conversation automatic? Or would it be necessary to wrap the arguments manually?
cjdoris commentedon Sep 28, 2026
PythonCall doesn't have any machinery for this directly.
Easiest is prob to make a little arg-making function like
then call like
or something along these lines.
Alexander-Barth commentedon Sep 30, 2026
Thanks a lot for your help!