Skip to content

Commit

Permalink
Use PythonCall to wrap Python ArviZ (#5)
Browse files Browse the repository at this point in the history
* Add CondaPkg.toml

* Replace PyCall packages with PythonCall equivalents

* Add LazyHelp utility

* Use LazyHelp utility for docs

* Update imports

* Update utilities to use PythonCall

* Update conversion and styles

* Update conversions to ELPDData

* Update plotting functions to use PythonCall

* Update examples.md

* Update docs deps

* Update docs

* Remove PyCall-specific CI code

* Use simpler caching action

* Cache CondaPkg artifacts

* Remove futures workflow

* Run formatter

* Remove build fiile

* Remove prefix

* Index axes from 0

* Use pywith in example

* Overload Py methods

* Delete unused macro

* Add topytype

* Simplify plotting functions

* Don't import PyCall

* Run formatter

* Convert styles list

* Fixes for utils

* Update some tests

* Enable strict docs building

* Remove setup code

* Remove todataframes

* Remove frompytype

* Remove convert_result

* Remove unused topandas method

* Replace DataFrames with Tables

* Remove conversions from Py to InferenceObjects

* Simplify rcparams code

* Fix rcparams bugs

* Use topytype utility

* Run formatter

* Fix topytype

* Update tests

* Increment lower Julia version bound

* Bump lower Julia version bound

* Update docs

* Don't reexport ArviZ

* Update docs

* Increment ArviZ version bound

* Also run CI on nightly
  • Loading branch information
sethaxen authored Aug 9, 2023
1 parent 5647210 commit 71afdf6
Show file tree
Hide file tree
Showing 31 changed files with 454 additions and 1,012 deletions.
14 changes: 0 additions & 14 deletions .github/workflows/Invalidations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PYTHON: "Conda" # use Julia's packaged Conda build for installing packages

jobs:
evaluate:
# Only run on PRs to the default branch.
Expand All @@ -24,17 +21,6 @@ jobs:
version: '1'
- uses: actions/checkout@v3
- uses: julia-actions/julia-buildpkg@v1
- name: Install Python ArviZ dependencies
run: |
using Pkg
Pkg.instantiate()
using Conda
# https://discourse.julialang.org/t/conda-not-installing-matplotlib-for-pyplot/96813/2
Conda.add("conda==23.1.0")
using ArviZPythonPlots
ArviZPythonPlots.initialize_arviz()
ArviZPythonPlots.initialize_pandas()
shell: julia --color=yes --project {0}
- uses: julia-actions/julia-invalidations@v1
id: invs_pr

Expand Down
45 changes: 14 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,55 +7,38 @@ on:
schedule:
- cron: "0 0 * * *"

env:
PYTHON: "Conda" # use Julia's packaged Conda build for installing packages

jobs:
test:
name: Julia ${{ matrix.julia-version }} - ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: ["1"]
os: [ubuntu-latest, windows-latest, macOS-latest]
julia-version: ["1", "1.8", "nightly"]
os: [ubuntu-latest]
include:
- julia-version: "1.6"
os: ubuntu-latest
- julia-version: "1"
os: windows-latest
- julia-version: "1"
os: macOS-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: x64
- name: Cache Julia artifacts
uses: actions/cache@v2
- uses: julia-actions/cache@v1
- name: Cache CondaPkg
id: cache-condaPkg
uses: actions/cache@v3
env:
cache-name: cache-artifacts
cache-name: cache-condapkg
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
path: .CondaPkg
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('docs/CondaPkg.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- name: Install wget for windows
if: matrix.os == 'windows-latest'
uses: crazy-max/ghaction-chocolatey@v2
with:
args: install wget
${{ runner.os }}-${{ env.cache-name }}-
- uses: julia-actions/julia-buildpkg@latest
- name: Install Python ArviZ dependencies
run: |
using Pkg
Pkg.instantiate()
using Conda
# https://discourse.julialang.org/t/conda-not-installing-matplotlib-for-pyplot/96813/2
Conda.add("conda==23.1.0")
using ArviZPythonPlots
ArviZPythonPlots.initialize_arviz()
ArviZPythonPlots.initialize_pandas()
shell: julia --color=yes --project {0}
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
Expand Down
24 changes: 13 additions & 11 deletions .github/workflows/documenter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ on:
tags: [v*]
pull_request:

env:
PYTHON: "Conda" # use Julia's packaged Conda build for installing packages

jobs:
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: julia-actions/cache@v1
- name: Cache CondaPkg
id: cache-condaPkg
uses: actions/cache@v3
env:
cache-name: cache-condapkg
with:
path: |
.CondaPkg
docs/.CondaPkg
key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('docs/CondaPkg.toml') }}
restore-keys: |
${{ runner.os }}-${{ env.cache-name }}-
- uses: julia-actions/julia-buildpkg@latest
- name: Setup Conda
run: |
using Pkg
Pkg.instantiate()
using Conda
# https://discourse.julialang.org/t/conda-not-installing-matplotlib-for-pyplot/96813/2
Conda.add("conda==23.1.0")
shell: julia --color=yes --project {0}
- uses: julia-actions/julia-docdeploy@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
69 changes: 0 additions & 69 deletions .github/workflows/futures.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
/docs/build
/test/*.log
.DS_Store
.CondaPkg
5 changes: 5 additions & 0 deletions CondaPkg.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
pandas = ""
matplotlib = ""
xarray = ""
arviz = ">=0.14.0"
19 changes: 10 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ version = "0.1.0"

[deps]
ArviZ = "131c737c-5715-5e2e-ad31-c244f01c1dc7"
Conda = "8f4d0f93-b110-5947-807f-2305c1781a2d"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
PythonPlot = "274fc56d-3b97-40fa-a1cd-1b4a50311bf9"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
ArviZ = "0.9"
ArviZ = "0.10"
ArviZExampleData = "0.1.5"
Conda = "1.0"
DataFrames = "0.20, 0.21, 0.22, 1.0"
CondaPkg = "0.2"
DimensionalData = "0.23, 0.24"
OrderedCollections = "1"
PyCall = "1.91.2"
PyPlot = "2.8.2"
PythonCall = "0.9"
PythonPlot = "1"
Reexport = "1"
julia = "1.6"
Tables = "1"
julia = "1.8"

[extras]
ArviZExampleData = "2f96bb34-afd9-46ae-bcd0-9b2d4372fe3c"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![Powered by NumFOCUS](https://img.shields.io/badge/powered%20by-NumFOCUS-orange.svg?style=flat&colorA=E1523D&colorB=007D8A)](https://numfocus.org)

ArviZPythonPlots.jl provides PyPlot-compatible plotting functions for exploratory analysis of Bayesian models using [ArviZ.jl](https://julia.arviz.org/).
It provides an interface to use the plotting functions in [Python ArviZ](https://python.arviz.org/) with Julia types.
It also re-exports all methods exported by both ArviZ.jl and [PyPlot.jl](https://github.com/JuliaPy/PyPlot.jl).
It uses [PythonCall.jl](https://github.com/cjdoris/PythonCall.jl) to provide an interface for using the plotting functions in [Python ArviZ](https://python.arviz.org/) with Julia types.
It also re-exports all methods exported by [PythonPlot.jl](https://github.com/JuliaPy/PythonPlot.jl).

See the [documentation](https://julia.arviz.org/ArviZPythonPlots) for details.
6 changes: 0 additions & 6 deletions deps/build.jl

This file was deleted.

5 changes: 1 addition & 4 deletions docs/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ ArviZExampleData = "2f96bb34-afd9-46ae-bcd0-9b2d4372fe3c"
ArviZPythonPlots = "4a6e88f0-2c8e-11ee-0601-e94153f0eada"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
PyPlot = "d330b81b-6aea-500a-939a-2ce795aea3ee"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"

[compat]
ArviZExampleData = "0.1.5"
Distributions = "0.25"
Documenter = "0.27"
PyCall = "1.0"
PyPlot = "2.0"
47 changes: 47 additions & 0 deletions docs/lazyhelp.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Documenter, Markdown, PythonCall

# adapted from https://github.com/AtelierArith/Kyulacs.jl for PythonCall
# MIT License
# Copyright (c) 2022 Satoshi Terasaki <[email protected]> and contributors

function get_signature(f)
inspect = pyimport("inspect")
try
return pyconvert(String, inspect.signature(f))
catch e
return ""
end
end

function gendocstr(h::LazyHelp)
o = h.o
for k in h.keys
o = pygetattr(o, k)
end
fname = pyhasattr(o, "__name__") ? pyconvert(String, o.__name__) : ""
sig = pyhasattr(o, "__call__") ? get_signature(o) : ""
fdoc = pyhasattr(o, "__doc__") ? pyconvert(String, o.__doc__) : ""

if isnothing(fdoc)
return """
$(fname)$(sig)
"""
else
return """
$(fdoc)
"""
end
end

function Documenter.Writers.HTMLWriter.mdconvert(h::LazyHelp, parent; kwargs...)
s = gendocstr(h)
# quote docstring `s` to prevent changing display result
m = Markdown.parse("""
```
$s
```
""")
return Documenter.Writers.HTMLWriter.mdconvert(m, parent; kwargs...)
end

Documenter.Utilities.MDFlatten.mdflatten(::IOBuffer, ::LazyHelp, ::Markdown.MD) = nothing
5 changes: 5 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using ArviZPythonPlots, Documenter
using ArviZPythonPlots: LazyHelp

include("lazyhelp.jl")

makedocs(;
modules=[ArviZPythonPlots],
Expand All @@ -17,7 +20,9 @@ makedocs(;
format=Documenter.HTML(;
prettyurls=haskey(ENV, "CI"), sidebar_sitename=false, canonical="stable"
),
doctest=false,
linkcheck=true,
strict=true,
)

deploydocs(;
Expand Down
Loading

4 comments on commit 71afdf6

@sethaxen
Copy link
Member 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 updated: JuliaRegistries/General/88578

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.1.0 -m "<description of version>" 71afdf6918efcbfb73e45004aeed792c2d0e0d52
git push origin v0.1.0

@sethaxen
Copy link
Member 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 updated: JuliaRegistries/General/88578

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.1.0 -m "<description of version>" 71afdf6918efcbfb73e45004aeed792c2d0e0d52
git push origin v0.1.0

Please sign in to comment.