Git Product home page Git Product logo

Comments (10)

stevengj avatar stevengj commented on June 16, 2024

Hmm, it seems like this might be a bug in ggplot, since there are no local variables if Python is embedded.... Or it could be a bug in inspect, since you'd still want it to define an empty f_locals in this case.

from pycall.jl.

stevengj avatar stevengj commented on June 16, 2024

Hmm,

using PyCall
@pyimport inspect
inspect.currentframe()

gives

PyError (PyObject_Call) <type 'exceptions.ValueError'>
ValueError('call stack is not deep enough',)

Similarly

@pyimport sys
sys._getframe()

gives a ValueError('call stack is not deep enough',), whereas in python I get:

>>> import sys
>>> sys._getframe()
<frame object at 0x106781b90>

So it seems that this is not a property of inspect, but rather a consequence of embedded Python not having a call stack before you call a function. I wonder if there is some way to "fake" this?

(But I still think that ggplot and/or inspect shouldn't depend on this.)

from pycall.jl.

randy3k avatar randy3k commented on June 16, 2024

So there are no quick solutions?

from pycall.jl.

jankatins avatar jankatins commented on June 16, 2024

You could open an Bugreport asking the patsy developers to work around in such situations.

from pycall.jl.

jankatins avatar jankatins commented on June 16, 2024

You could try to change the line to return cls([<empty list?>, <empty list?>], _ALL_FUTURE_FLAGS) (I'm not sure what type frame.f_locals and frame.f_globals are) the and see if that would make it work.

That "environment" is used in ggplot to evaluate things like ggplot.aes(x="x+y",y="np.log(assets)"). So if julia calls have no access to the underlying functions, you can only use column names (which are added to the environment in a later step).

Another obstacle could be that ggplot expects data as pandas DataFrames. Not sure how that library works in Julia (I've not yet used Julia).

from pycall.jl.

malmaud avatar malmaud commented on June 16, 2024

Try using pyeval instead of pycall

from pycall.jl.

stevengj avatar stevengj commented on June 16, 2024

@malmaud, good suggestion. Looking at the source code for PyEval_EvalCodeEx, I see that it indeed creates a frame while it is executing:

julia> pyeval("i.currentframe()", i=PyCall.inspect)
PyObject <frame object at 0x3223793a0>

from pycall.jl.

stevengj avatar stevengj commented on June 16, 2024

In principle, it looks like PyCall could create its own stack frame by doing something like this internal function. In practice, I'm a bit leery of relying on undocumented internals like this, since ordinary Python code should not rely on inspect.currentframe() existing, and one can use pyeval as a workaround for the rare exceptions.

from pycall.jl.

tkf avatar tkf commented on June 16, 2024

I think this issue should be fixed in upstreams. FYI here is my PR to matplotlib for fixing this issue: matplotlib/matplotlib#12771. (Maybe it's faster to get a fix if you include an example when reporting it?)

from pycall.jl.

NightMachinery avatar NightMachinery commented on June 16, 2024

Consider adding this to the error message:

Embedded Python does not have a stack frame. Use pyeval as a workaround.

It'll save some confusion.

from pycall.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.