-
Notifications
You must be signed in to change notification settings - Fork 61
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
adjust to use getproperty over getindex with PyObject values #254
Conversation
Ooops, this change is on master in PyCall but not yet released. Need to wait for a new release. |
PyCall 1.90.0 is now released. |
x = sympy.Symbol("x") | ||
y = sympy.sin(x) | ||
y[:subs](x, sympy.pi) |> float | ||
z = y.subs(x, sympy.pi) | ||
convert(Float64, z) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|> float
or |> Float64
no longer works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, surprisingly, I saw this when trying to run the README examples:
julia> using PyCall
julia> sympy = pyimport("sympy")
PyObject <module 'sympy' from '/Users/verzani/.julia/conda/3/lib/python3.7/site-packages/sympy/__init__.py'>
julia> x = sympy.Symbol("x")
PyObject x
julia> y = sympy.sin(x)
PyObject sin(x)
julia> z = y.subs(x, sympy.pi)
PyObject 0
julia> float(z)
ERROR: MethodError: no method matching AbstractFloat(::PyObject)
Closest candidates are:
AbstractFloat(::Bool) at float.jl:252
AbstractFloat(::Int8) at float.jl:253
AbstractFloat(::Int16) at float.jl:254
...
Stacktrace:
[1] float(::PyObject) at ./float.jl:271
[2] top-level scope at none:0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah, that's because constructors no longer fall back to convert.
I tried adding the constructor methods in manually, but then I got a massive slowdown: JuliaLang/julia#27599
I should probably add a float
method, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t rely on it here, but it might be helpful. I’d like to see how much of SymPy can be trimmed out now that the getproperty feature is used. I think quite a bit.
Here is use case in the wild
https://stackoverflow.com/questions/54959482/converting-pycall-pyobject-decimal-to-julia-float
On Thu, Feb 28, 2019 at 5:16 PM Steven G. Johnson ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In README.md
<#254 (comment)>:
> x = sympy.Symbol("x")
y = sympy.sin(x)
-y[:subs](x, sympy.pi) |> float
+z = y.subs(x, sympy.pi)
+convert(Float64, z)
Oh yeah, that's because constructors no longer fall back to convert.
I tried adding the constructor methods in manually, but then I got a
massive slowdown: JuliaLang/julia#27599
<JuliaLang/julia#27599>
I should probably add a float method, though.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#254 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAZvTGYfSDwGB_7XV6oX0t-5WRXj_OG3ks5vSFVbgaJpZM4a00gx>
.
--
John Verzani
Department of Mathematics
College of Staten Island, CUNY
[email protected]
|
PyCall now deprecates
getindex
to usegetproperty
for dot-field overloading. This adjusts SymPy to use this style and adds agetproperty
method. This diversifies the calling style for sympy methods.