Skip to content

Commit

Permalink
Merge pull request #49 from jverzani/bool3
Browse files Browse the repository at this point in the history
bool3
  • Loading branch information
jverzani authored May 24, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents e200066 + 22ed82c commit a8981cc
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymPyPythonCall"
uuid = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
authors = ["jverzani <jverzani@gmail.com> and contributors"]
version = "0.2.6"
version = "0.3.0"


[deps]
@@ -28,7 +28,7 @@ PythonCall = "0.9"
SpecialFunctions = "0.8, 0.9, 0.10, 1.0, 2"
Symbolics = "5"
SymbolicUtils = "1"
SymPyCore = "0.1.6, 1"
SymPyCore = "0.2, 1"
julia = "1.6.1"


20 changes: 18 additions & 2 deletions src/python_connection.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
## PythonCall specific usage
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py, S<:Sym} = x
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py,
S<:Sym{PythonCall.Py}} = x
Base.convert(::Type{S}, x::T) where {T<:PythonCall.Py, S <: SymbolicObject} = Sym(x)

SymPyCore._convert(::Type{T}, x) where {T} = pyconvert(T, x)
function SymPyCore._convert(::Type{Bool}, x::Py)
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanTrue) && return true
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanFalse) && return false
pyisinstance(x, _sympy_.logic.boolalg.BooleanTrue) && return true
pyisinstance(x, _sympy_.logic.boolalg.BooleanFalse) && return false
pyconvert(Bool, pybool(x))
end

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

## Modifications for ↓, ↑
Sym(x::Nothing) = Sym(pybuiltins.None)

2 comments on commit a8981cc

@jverzani
Copy link
Owner 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/107593

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 v0.3.0 -m "<description of version>" a8981cccb03111f1e9cdf976c5ab928c075b6dd8
git push origin v0.3.0

Please sign in to comment.