Skip to content

Commit

Permalink
Merge pull request #570 from AayushSabharwal/as/table-traits
Browse files Browse the repository at this point in the history
fix: conversion of solutions to DataFrames
  • Loading branch information
ChrisRackauckas authored Dec 26, 2023
2 parents 3bfb948 + e30c782 commit d2ab06f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ ChainRules = "1.58.0"
ChainRulesCore = "1.18"
CommonSolve = "0.2.4"
ConstructionBase = "1.5"
DataFrames = "1.6"
Distributed = "1.9"
DocStringExtensions = "0.9"
EnumX = "1"
Expand All @@ -64,6 +65,7 @@ IteratorInterfaceExtensions = "^1"
LinearAlgebra = "1.9"
Logging = "1.9"
Markdown = "1.9"
ModelingToolkit = "8.74"
PartialFunctions = "1.1"
PrecompileTools = "1.2"
Preferences = "1.3"
Expand All @@ -88,7 +90,9 @@ julia = "1.9"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DelayDiffEq = "bcd4f6db-9728-5f36-b5f7-82caef46ccdb"
ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Expand All @@ -102,4 +106,4 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[targets]
test = ["Pkg", "PyCall", "PythonCall", "SafeTestsets", "Test", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions"]
test = ["Pkg", "PyCall", "PythonCall", "SafeTestsets", "Test", "StaticArrays", "StochasticDiffEq", "Aqua", "Zygote", "PartialFunctions", "DataFrames", "ModelingToolkit", "OrdinaryDiffEq"]
2 changes: 1 addition & 1 deletion src/tabletraits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function Tables.rows(sol::AbstractTimeseriesSolution)
names = [
:timestamp,
(isempty(syms) ? (Symbol("value", i) for i in 1:N) :
(syms[i] for i in 1:N))...,
(getname(syms[i]) for i in 1:N))...,
]
types = Type[eltype(sol.t), (eltype(sol.u[1]) for i in 1:N)...]
else
Expand Down
12 changes: 12 additions & 0 deletions test/traits.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using SciMLBase, Test
using ModelingToolkit, OrdinaryDiffEq, DataFrames

@test SciMLBase.Tables.isrowtable(ODESolution)
@test SciMLBase.Tables.isrowtable(RODESolution)
Expand All @@ -7,3 +8,14 @@ using SciMLBase, Test
@test !SciMLBase.Tables.isrowtable(SciMLBase.LinearSolution)
@test !SciMLBase.Tables.isrowtable(SciMLBase.QuadratureSolution)
@test !SciMLBase.Tables.isrowtable(SciMLBase.OptimizationSolution)

@variables t x(t)=1
D = Differential(t)
eqs = [D(x) ~ -x]
@named sys = ODESystem(eqs)
prob = ODEProblem(sys)
sol = solve(prob, Tsit5(), tspan=(0.0, 1.0))
df = DataFrame(sol)
@test size(df) == (length(sol.u), 2)
@test df.timestamp == sol.t
@test df.x == sol[x]

0 comments on commit d2ab06f

Please sign in to comment.