Skip to content

Commit

Permalink
add ODESolution (and SciMLEnsembleSolution) to DataFrame support (con…
Browse files Browse the repository at this point in the history
…ditional on 1.9)
  • Loading branch information
oscardssmith committed Jul 14, 2023
1 parent 605824a commit 40abe8d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"

[weakdeps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"

[extensions]
SciMLBaseDataFramesExt = "DataFrames"

[compat]
ADTypes = "0.1.3"
ArrayInterface = "6, 7"
Expand Down
28 changes: 28 additions & 0 deletions ext/SciMLBaseDataFramesExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module SciMLBaseDataFramesExt
using SciMLBase, DataFrames

function DataFrames.DataFrame(sol::EnsembleSolution, idxs::AbstractVector)
@assert allequal(getproperty.(sol.u, :t)) "solutions must have shared timesteps"
data = sol[:, idxs]
i_max, j_max, _ = size(data)
v = ["t"=>sol[1].t]
for (i, s) in enumerate(sol.u)
for idx in idxs
push!(v, string("sol ", i, ": ", idx)=>s[idx])
end
end
DataFrame(v)

Check warning on line 14 in ext/SciMLBaseDataFramesExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/SciMLBaseDataFramesExt.jl#L4-L14

Added lines #L4 - L14 were not covered by tests
end

function DataFrames.DataFrame(sol::ODESolution, idxs::AbstractVector)
@assert allequal(getproperty.(sol.u, :t)) "solutions must have shared timesteps"
data = sol[:, idxs]
i_max, j_max, _ = size(data)
v = ["t"=>sol[1].t]
for idx in idxs
push!(v, string("sol ", i, ": ", idx)=>s[idx])
end
DataFrame(v)

Check warning on line 25 in ext/SciMLBaseDataFramesExt.jl

View check run for this annotation

Codecov / codecov/patch

ext/SciMLBaseDataFramesExt.jl#L17-L25

Added lines #L17 - L25 were not covered by tests
end

end

0 comments on commit 40abe8d

Please sign in to comment.