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

adjust to use getproperty over getindex with PyObject values #254

Merged
merged 2 commits into from
Feb 28, 2019

Conversation

jverzani
Copy link
Collaborator

PyCall now deprecates getindex to use getproperty for dot-field overloading. This adjusts SymPy to use this style and adds a getproperty method. This diversifies the calling style for sympy methods.

@jverzani
Copy link
Collaborator Author

Ooops, this change is on master in PyCall but not yet released. Need to wait for a new release.

@stevengj
Copy link
Member

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)
Copy link
Member

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?

Copy link
Collaborator Author

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

Copy link
Member

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.

Copy link
Collaborator Author

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.

@jverzani jverzani merged commit ff91a83 into JuliaPy:master Feb 28, 2019
@jverzani jverzani deleted the getproperty branch February 28, 2019 20:52
@jverzani
Copy link
Collaborator Author

jverzani commented Mar 2, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants