Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single-index access to matrix results in confusing error #432

Open
PhilReinhold opened this issue Dec 5, 2023 · 1 comment
Open

Single-index access to matrix results in confusing error #432

PhilReinhold opened this issue Dec 5, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@PhilReinhold
Copy link

Affects: JuliaCall

Describe the bug

from juliacall import Main as jl
z = jl.seval("[0 1; 2 3]")
z[0]

results in the stack trace

File ~/.julia/packages/PythonCall/wXfah/src/jlwrap/array.jl:310, in __getitem__(self, k)
    308     return bool(len(self))
    309 def __getitem__(self, k):
--> 310     return self._jl_callmethod($(pyjl_methodnum(pyjlarray_getitem)), k)
    311 def __setitem__(self, k, v):
    312     self._jl_callmethod($(pyjl_methodnum(pyjlarray_setitem)), k, v)

JuliaError: "an error occurred while setting an error"

I would expect z[0] to have the same output as list(z)[0]. The latter outputs just 0. Fair enough if you want to choose a different semantics though, since z[0,:] is another reasonable choice. Regardless, the error message is confusing as it stands.

Your system

  • macos 13.6
  • python 3.11.4
  • julia 1.9.4
  • juliacall 0.9.15
    JuliaPkg Status
    /Users/pcrein/.pyenv/versions/3.11.4/envs/pyqsr-3.11.4/julia_env/pyjuliapkg/juliapkg.json (empty project)
    Julia 1.9.4 @ /Users/pcrein/.julia/juliaup/julia-1.9.4+0.aarch64.apple.darwin14/bin/julia
@PhilReinhold PhilReinhold added the bug Something isn't working label Dec 5, 2023
@cjdoris
Copy link
Collaborator

cjdoris commented Dec 5, 2023

The particular error message you're seeing is a bug. As it says, it tried to throw a different (better) error, but that failed for some reason so it threw this generic message instead. I can look into why.

However its correct that z[0] is disallowed for matrices - there is no standard convention for what that should mean (Julia and numpy return very different things) so this package defines neither.

You can wrap the array with numpy.asarray(z) if you'd like to use numpy's behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants