Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataFrame export #469

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 3 additions & 3 deletions src/ensemble/ensemble_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,16 @@


Base.@propagate_inbounds function Base.getindex(x::AbstractEnsembleSolution, ::Colon, s)
return [xi[s] for xi in x]
return VectorOfArray([xi[s] for xi in x])

Check warning on line 203 in src/ensemble/ensemble_solutions.jl

View check run for this annotation

Codecov / codecov/patch

src/ensemble/ensemble_solutions.jl#L203

Added line #L203 was not covered by tests
end

Base.@propagate_inbounds function Base.getindex(x::AbstractEnsembleSolution, ::Colon, args::Colon...)
return invoke(getindex, Tuple{RecursiveArrayTools.AbstractVectorOfArray, Colon, typeof.(args)...}, x, :, args...)
end
Base.@propagate_inbounds function Base.getindex(x::AbstractEnsembleSolution, ::Colon, args::Int...)
return [xi[args...] for xi in x]
return VectorOfArray([xi[args...] for xi in x])

Check warning on line 210 in src/ensemble/ensemble_solutions.jl

View check run for this annotation

Codecov / codecov/patch

src/ensemble/ensemble_solutions.jl#L210

Added line #L210 was not covered by tests
end

function (sol::AbstractEnsembleSolution)(args...; kwargs...)
[s(args...; kwargs...) for s in sol]
VectorOfArray([s(args...; kwargs...) for s in sol])

Check warning on line 214 in src/ensemble/ensemble_solutions.jl

View check run for this annotation

Codecov / codecov/patch

src/ensemble/ensemble_solutions.jl#L214

Added line #L214 was not covered by tests
end
6 changes: 3 additions & 3 deletions src/solutions/solution_interface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@
if has_sys(A.prob.f) && all(Base.Fix1(is_param_sym, A.prob.f.sys), sym) ||
!has_sys(A.prob.f) && has_paramsyms(A.prob.f) &&
all(in(getparamsyms(A)), Symbol.(sym))
return getindex.((A,), sym)
return VectorOfArray(getindex.((A,), sym))

Check warning on line 81 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L81

Added line #L81 was not covered by tests
else
return [getindex.((A,), sym, i) for i in eachindex(A)]
return VectorOfArray([getindex.((A,), sym, i) for i in eachindex(A)])

Check warning on line 83 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L83

Added line #L83 was not covered by tests
end
else
i = sym
Expand Down Expand Up @@ -110,7 +110,7 @@
observed(A, sym, :)
end
elseif i isa Base.Integer || i isa AbstractRange || i isa AbstractVector{<:Base.Integer}
A[i, :]
VectorOfArray(A[i, :])

Check warning on line 113 in src/solutions/solution_interface.jl

View check run for this annotation

Codecov / codecov/patch

src/solutions/solution_interface.jl#L113

Added line #L113 was not covered by tests
else
error("Invalid indexing of solution")
end
Expand Down
Loading