Skip to content

Commit 7bb2e90

Browse files
paldaymich11
andauthored
use PythonCall instead of PyCall (#4)
* use PythonCall instead of PyCall * remove build.jl * add concurrency blob * drop stale comment * README update * Update README.md --------- Co-authored-by: mich11 <[email protected]>
1 parent bcce447 commit 7bb2e90

File tree

9 files changed

+189
-210
lines changed

9 files changed

+189
-210
lines changed

.github/workflows/CI.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
name: CI
2+
concurrency:
3+
group: ${{ github.head_ref }}.ci
4+
cancel-in-progress: true
25
on:
36
push:
47
paths-ignore:
@@ -18,7 +21,7 @@ jobs:
1821
fail-fast: false
1922
matrix:
2023
version:
21-
- '1' # currently 1.6, but will hopefully change in the near future
24+
- '1'
2225
- '1.6'
2326
- 'nightly'
2427
os:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ docs/site/
2222
# committed for packages, but should be committed for applications that require a static
2323
# environment.
2424
Manifest.toml
25+
26+
.CondaPkg/

CondaPkg.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
channels = ["anaconda", "conda-forge"]
2+
[deps]
3+
# Conda package names and versions
4+
python = ">=3.5,<4"
5+
6+
# CondaPkg uses mamba by default
7+
fooof = ">=1.0, <2"
8+
9+
[pip.deps]
10+
# Pip package names and versions

Project.toml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
name = "PyFOOOF"
22
uuid = "bb993ee8-2a51-46a1-a315-55ff424041b4"
33
authors = ["Beacon Biosignals, Inc."]
4-
version = "0.1.0"
4+
version = "0.2.0"
55

66
[deps]
7-
PyCall = "438e738f-606a-5dbb-bf0a-cddfbfd45ab0"
7+
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
8+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
89

910
[compat]
10-
PyCall = "1.90"
11+
Aqua = "0.5, 0.6"
12+
PythonCall = "0.9"
13+
Reexport = "1"
1114
julia = "1.6"
15+
16+
[extras]
17+
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
18+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
19+
20+
[targets]
21+
test = ["Aqua", "Test"]

README.md

Lines changed: 131 additions & 176 deletions
Large diffs are not rendered by default.

deps/build.jl

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/PyFOOOF.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
module PyFOOOF
22

3-
using PyCall
4-
53
#####
6-
##### init
4+
##### Dependencies
75
#####
86

9-
const fooof = PyNULL()
7+
using Reexport
8+
9+
@reexport using PythonCall
10+
11+
######
12+
###### Actual functionality
13+
######
14+
15+
const fooof = PythonCall.pynew()
1016

1117
function __init__()
1218
# all of this is __init__() so that it plays nice with precompilation
13-
# see https://github.com/JuliaPy/PyCall.jl/#using-pycall-from-julia-modules
14-
copy!(fooof, pyimport("fooof"))
19+
# see https://github.com/cjdoris/PythonCall.jl/blob/5ea63f13c291ed97a8bacad06400acb053829dd4/src/Py.jl#L85-L96
20+
PythonCall.pycopy!(fooof, pyimport("fooof"))
1521
# don't eval into the module while precompiling; this breaks precompilation
16-
# of downstream modules
22+
# of downstream modules (see #4)
1723
if ccall(:jl_generating_output, Cint, ()) == 0
1824
# delegate everything else to fooof
1925
for pn in propertynames(fooof)

test/Project.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.

test/runtests.jl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
using PyCall
1+
using Aqua
22
using PyFOOOF
33
using Test
44

5+
@testset "Aqua" begin
6+
Aqua.test_all(PyFOOOF; ambiguities=false)
7+
end
8+
59
# test that this works
610
fooof = PyFOOOF.fooof
711

@@ -24,19 +28,23 @@ set_random_seed = pyimport("fooof.sim.utils").set_random_seed
2428

2529
f_range = [1, 50]
2630
ap_params = [20, 2]
27-
# XXX PyCall's aggressive conversion to NumPy arrays creates problems here
28-
# so we force it be treated as raw Python code (py-prefix)
29-
# and NOT be converted to a native Julia array (o-suffix)
30-
gauss_params = py"[[10, 1.0, 2.5], [20, 0.8, 2], [32, 0.6, 1]]"
31+
# FOOOF requires a list of lists for this, so we need to guarantee
32+
# that Vector{<:Number} is not coverted to NumPy arrays
33+
# NB: broadcasting so that we don't have a list of Vector{<:Number}, which
34+
# would become a a list of NumPy arrays
35+
gauss_params = pylist.([[10, 1.0, 2.5], [20, 0.8, 2], [32, 0.6, 1]])
3136
nlv = 0.1
3237
set_random_seed(21)
3338

3439
freqs, spectrum = gen_power_spectrum(f_range, ap_params, gauss_params, nlv)
3540

36-
fm = FOOOF(; peak_width_limits=py"[1, 8]"o, max_n_peaks=6, min_peak_height=0.4)
41+
fm = FOOOF(; peak_width_limits=[1, 8], max_n_peaks=6, min_peak_height=0.4)
3742
fm.fit(freqs, spectrum)
3843

39-
ground_truth = float.(py"$(gauss_params)")
40-
actual_estimates = fm.gaussian_params_
44+
# not worth adding a compat dependency just to get stack() for one test,
45+
# ew this is messy without stack()
46+
ground_truth = mapreduce(x -> pyconvert(Vector{Float64}, x)',
47+
vcat, gauss_params; init=Matrix{Float64}(undef, 0, 3))
48+
actual_estimates = pyconvert(Matrix, fm.gaussian_params_)
4149
expected_estimates = [9.82 0.91 2.43; 20.03 0.82 1.94; 31.85 0.57 1.11]
4250
@test actual_estimates expected_estimates atol=0.01

0 commit comments

Comments
 (0)