Skip to content

Commit

Permalink
Bool3 (#546)
Browse files Browse the repository at this point in the history
* move SymPyPyCall -> SymPy; breaking change

* Bool3, bump
  • Loading branch information
jverzani authored May 24, 2024
1 parent a6e74db commit bb45773
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "SymPy"
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
version = "2.0.1"
version = "2.1.0"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand All @@ -17,7 +17,7 @@ LinearAlgebra = "<0.0.1, 1.6"
PyCall = "1.96.2"
SpecialFunctions = "0.7, 0.8, 0.8, 0.10, 1, 2"
SymbolicUtils = "1"
SymPyCore = "0.1.6, 1"
SymPyCore = "0.2, 1"
julia = "1.6"

[extras]
Expand Down
1 change: 0 additions & 1 deletion src/SymPy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ include(joinpath(core_src_path, "gen_methods_sympy.jl"))
include(joinpath(core_src_path, "additional_methods_sympy.jl"))
include(joinpath(core_src_path, "show_sympy.jl"))


include("python_connection.jl")

end # module
23 changes: 16 additions & 7 deletions src/python_connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
# PyObject are needed for that.

Base.convert(::Type{S}, x::Sym{T}) where {T<:PyObject, S<:Sym} = x
Base.convert(::Type{S}, x::Sym{T}) where {T<:PyObject, S<:Sym{PyObject}} = x
Base.convert(::Type{S}, x::T) where {T<:PyObject, S <: SymbolicObject} = Sym(x)

SymPyCore._convert(::Type{T}, x) where {T} = convert(T, x)

function SymPyCore._convert(::Type{Bool}, x::PyObject)
x == _sympy_.logic.boolalg.BooleanTrue && return true
x == _sympy_.logic.boolalg.BooleanFalse && return false
Expand All @@ -22,13 +24,20 @@ function SymPyCore._convert(::Type{Bool}, x::PyObject)
error("Can't convert $x to boolean")
end


## Modifications for ↓, ↑
Sym(x::Nothing) = Sym(PyObject(nothing))
Sym(x::Bool) = Sym(PyObject(x))
Sym(x::Integer) = Sym(_sympy_.Integer(x)) # slight improvement over sympify
Sym(x::AbstractFloat) = Sym(_sympy_.Float(x))

function SymPyCore.Bool3(x::Sym{T}) where {T <: PyObject}
y = (x)
isnothing(y) && return nothing
if hasproperty(y, "is_Boolean")
if convert(Bool, y.is_Boolean)
return SymPyCore._convert(Bool, y)
end
elseif hasproperty(y, "__bool__")
if convert(Bool, y != (Sym(nothing)))
return convert(Bool, y.__bool__())
end
end
return nothing
end

SymPyCore.:(x::PyObject) = x
SymPyCore.:(d::Dict) = Dict((k) => (v) for (k,v) pairs(d))
Expand Down

2 comments on commit bb45773

@jverzani
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/107594

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.1.0 -m "<description of version>" bb4577394e7c035478ab547103669d98223ff75f
git push origin v2.1.0

Please sign in to comment.