From 1bf0a2a69d16f63ba0ca06fb11dddfb85e1b55b3 Mon Sep 17 00:00:00 2001 From: Kyungdahm Yun Date: Wed, 10 Jun 2020 22:49:54 -0700 Subject: [PATCH] Adapt to DataFrames index change (http://JuliaData/DataFrames.jl#2199) --- src/unit.jl | 4 ++-- src/util/calibrate.jl | 2 +- src/util/simulate.jl | 2 +- test/unit.jl | 16 ++++++++-------- test/util/simulate.jl | 14 +++++++------- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/unit.jl b/src/unit.jl index 6c9a3c5c..9be4e8d4 100644 --- a/src/unit.jl +++ b/src/unit.jl @@ -21,14 +21,14 @@ deunitfy(v, u) = deunitfy(unitfy(v, u)) import DataFrames: DataFrame, DataFrames unitfy(df::DataFrame, U::Vector) = begin r = DataFrame() - for (n, c, u) in zip(names(df), eachcol(df), U) + for (n, c, u) in zip(propertynames(df), eachcol(df), U) r[!, n] = unitfy.(c, u) end r end unitfy(df::DataFrame) = begin p = r"(.+)\(([^\(\)]+)\)$" - M = match.(p, String.(names(df))) + M = match.(p, names(df)) u(m::RegexMatch) = eval(:(@u_str($(m.captures[2])))) u(m) = nothing U = u.(M) diff --git a/src/util/calibrate.jl b/src/util/calibrate.jl index ef38e307..436a6283 100644 --- a/src/util/calibrate.jl +++ b/src/util/calibrate.jl @@ -16,7 +16,7 @@ calibrate(S::Type{<:System}, obs, configs; index="context.clock.tick", target, p elseif metric == :prmse metric = (E, O) -> ((E - O) ./ O).^2 end - NT = DataFrames.make_unique([names(obs)..., T...], makeunique=true) + NT = DataFrames.make_unique([propertynames(obs)..., T...], makeunique=true) T1 = NT[end-n+1:end] residual(c) = begin est = simulate(S; config=c, index=index, target=target, verbose=false, kwargs...) diff --git a/src/util/simulate.jl b/src/util/simulate.jl index f6585b62..0b961337 100644 --- a/src/util/simulate.jl +++ b/src/util/simulate.jl @@ -49,7 +49,7 @@ format(m::Simulation; nounit=false, long=false) = begin end if long i = collect(keys(m.index)) - t = setdiff(names(r), i) + t = setdiff(propertynames(r), i) r = DataFrames.stack(r, t, i) end r diff --git a/test/unit.jl b/test/unit.jl index 230b88c5..5853dbcb 100644 --- a/test/unit.jl +++ b/test/unit.jl @@ -86,19 +86,19 @@ using DataFrames @testset "dataframe auto" begin df = DataFrame() z = [0] - df[!, Symbol("a (g/cm^2)")] = z - df[!, Symbol("c (a)(b)(s)")] = z - df[!, Symbol("b ()")] = z - df[!, Symbol("d")] = z + df."a (g/cm^2)" = z + df."c (a)(b)(s)" = z + df."b ()" = z + df."d" = z r = Cropbox.unitfy(df) @test Cropbox.unit(eltype(r[!, 1])) == u"g/cm^2" @test Cropbox.unit(eltype(r[!, 2])) == u"s" @test Cropbox.unit(eltype(r[!, 3])) == u"NoUnits" @test Cropbox.unit(eltype(r[!, 4])) == u"NoUnits" N = names(r) - @test N[1] == Symbol("a") - @test N[2] == Symbol("c (a)(b)") - @test N[3] == Symbol("b ()") - @test N[4] == Symbol("d") + @test N[1] == "a" + @test N[2] == "c (a)(b)" + @test N[3] == "b ()" + @test N[4] == "d" end end diff --git a/test/util/simulate.jl b/test/util/simulate.jl index 17459554..69bb890e 100644 --- a/test/util/simulate.jl +++ b/test/util/simulate.jl @@ -11,7 +11,7 @@ using Dates r = simulate(SSimulate, stop=n) @test r isa DataFrame @test size(r, 1) == (n+1) - @test names(r) == [:tick, :a, :b] + @test propertynames(r) == [:tick, :a, :b] @test r[end, :tick] == (n+1)u"hr" @test r[end, :a] == 1 @test r[end, :b] == n @@ -20,10 +20,10 @@ using Dates @test r[end, :b] == 2n r = simulate(SSimulate, stop=n, target=[:b]) @test size(r, 2) == 2 - @test names(r) == [:tick, :b] + @test propertynames(r) == [:tick, :b] r = simulate(SSimulate, stop=n, index=:b, target=[:b]) @test size(r, 2) == 1 - @test names(r) == [:b] + @test propertynames(r) == [:b] end @testset "stop" begin @@ -87,9 +87,9 @@ using Dates ] n = 1 r = simulate(SSimulateLayout, L, stop=n) - @test names(r[1]) == [:tick, :a] - @test names(r[2]) == [:t, :i, :a, :B] - @test names(r[3]) == [:tick, :step] + @test propertynames(r[1]) == [:tick, :a] + @test propertynames(r[2]) == [:t, :i, :a, :B] + @test propertynames(r[3]) == [:tick, :step] @test r[1][end, :tick] == r[2][end, :t] == r[3][end, :tick] == (n+1)u"hr" @test r[1][end, :a] == 0 @test r[2][end, :B] == 2 @@ -183,7 +183,7 @@ using Dates g => (1, 2) ~ track::Tuple end r = simulate(SSimulateExtractable) - N = names(r) + N = propertynames(r) # default = Union{Number,Symbol,AbstractString,AbstractDateTime} @test :a ∈ N @test :b ∈ N