Skip to content

ellipses (...) as indices on numpy array: #827

Description

@Alexander-Barth

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) :

def test_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))

Unfortunately, the produces the error:

ERROR: Python: TypeError: expecting 3 indices, got 2
Python stacktrace:
 [1] __getitem__
   @ ~/.julia/packages/PythonCall/83z4q/src/JlWrap/array.jl:350
 [2] test_ellipsis
   @ test_ellipsis ~/src/NEDAS-test/NEDAS_tutorials/test_ellipsis.py:2

Describe the solution you'd like

Could indexing of ellipses be supported in PythonCall.jl for numpy arrays ?

Describe alternatives you've considered

I could create a np.array from the julia side, for example:

np = pyimport("numpy")
pyimport("test_ellipsis").test_ellipsis(np.asarray(randn(2,2,2)))

Additional context

I am using julia 1.12 on Linux with PythonCall v0.9.31 and Numpy 2.5.3.

Btw, thanks for the great package!!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions