JuliaPy / SymPy.jl

Julia interface to SymPy via PyCall
http://juliapy.github.io/SymPy.jl/
MIT License
269 stars 61 forks source link

Missing property is_rational #369

Closed mzaffalon closed 4 years ago

mzaffalon commented 4 years ago

It looks like is_rational is not set for certain types on master

julia> x = Sym(2.5)
2.50000000000000

julia> SymPy.pycall_hasproperty(x, :is_rational)
true

julia> isnothing(x.__pyobject__.is_rational)
true

This leads to the following error:

julia> N(x, 256)
ERROR: TypeError: non-boolean (Nothing) used in boolean context
Stacktrace:
 [1] N(::Sym, ::Int64; kwargs::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}) at C:\Users\michele.zaffalon\.julia\packages\SymPy\yYD8e\src\numbers.jl:286
 [2] N(::Sym, ::Int64) at C:\Users\michele.zaffalon\.julia\packages\SymPy\yYD8e\src\numbers.jl:277
 [3] top-level scope at REPL[20]:1

I forgot most of my Python, but it looks like sympy also fails to set the property correctly. Would in this case make sense e.g. in https://github.com/JuliaPy/SymPy.jl/blob/382a805b7c4ec1b117b162437dc881787bc53978/src/numbers.jl#L53-L54, to return

pycall_hasproperty(x, :is_rational) && return (isnothing(x.is_rational) ? false : x.is_rational)
jverzani commented 4 years ago

Yes, that seems to make sense. I'll try to put in a PR when I get a chance. Thanks!

mzaffalon commented 4 years ago

Do you mind if I take a stab at it?

jverzani commented 4 years ago

Sorry, missed this. I just did it.

On Mon, Aug 31, 2020 at 3:50 PM Michele Zaffalon notifications@github.com wrote:

Do you mind if I take a stab at it?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/JuliaPy/SymPy.jl/issues/369#issuecomment-684001171, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADG6TEPSUQUZB4OZUTOQJ3SDP5IHANCNFSM4QQST55A .

-- John Verzani Department of Mathematics College of Staten Island, CUNY verzani@math.csi.cuny.edu