Skip to content

Commit

Permalink
Merge pull request #94 from TuringLang/csp/describe-fix
Browse files Browse the repository at this point in the history
Describe bugfixes
  • Loading branch information
cpfiffer authored Apr 23, 2019
2 parents 8e97996 + 4acd398 commit ad77a88
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/chains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ function Chains(val::AbstractArray{A,3},

# Ensure that we have a hashedsummary key in info.
if !in(:hashedsummary, keys(info))
s = (hash(0), ChainDataFrame("", DataFrame()))
empty_df_vec = [ChainDataFrame("", DataFrame())]
s = (hash(0), empty_df_vec)
info = merge(info, (hashedsummary = Ref(s),))
end

Expand Down Expand Up @@ -314,12 +315,12 @@ function Base.show(io::IO, c::Chains)
if s[1] == h
show(io, s[2])
else
new_summary = summarystats(c)
new_summary = describe(c)
c.info.hashedsummary.x = (h, new_summary)
show(io, new_summary)
end
else
show(io, summarystats(c, suppress_header=true))
show(io, describe(c, suppress_header=true))
end
end

Expand Down Expand Up @@ -612,7 +613,8 @@ function _use_showall(c::AbstractChains, section::Symbol)
return false
end

function _clean_sections(c::AbstractChains, sections::Vector{Symbol})
function _clean_sections(c::AbstractChains, sections::Union{Vector{Symbol}, Symbol})
sections = sections isa AbstractArray ? sections : [sections]
ks = collect(keys(c.name_map))
return ks sections
end
Expand Down
4 changes: 3 additions & 1 deletion src/stats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ function describe(io::IO,
sections::Union{Symbol, Vector{Symbol}}=Symbol[:parameters],
args...
)
dfs = [summarystats(c, showall=showall, args...), quantile(c, showall=showall, q=q)]
dfs = [summarystats(c, showall=showall, sections=sections, etype=etype, args...),
quantile(c, showall=showall, sections=sections, q=q)]
return dfs
end

Expand Down Expand Up @@ -177,6 +178,7 @@ function quantile(chn::AbstractChains;
return summarize(chn, funs...;
func_names=func_names,
showall=showall,
sections=sections,
name = "Quantiles")
end

Expand Down
5 changes: 3 additions & 2 deletions src/summarize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ ChainDataFrame(df::DataFrame) = ChainDataFrame("", df)

Base.size(c::ChainDataFrame) = size(c.df)
Base.names(c::ChainDataFrame) = names(c.df)

function Base.show(io::IO, c::ChainDataFrame)
println(io, c.name)
show(io, c.df, summary = false, allrows=true)
show(io, c.df, summary = false, allrows=true, allcols=true)
end

Base.getindex(c::ChainDataFrame, args...) = getindex(c.df, args...)
Base.getindex(c::ChainDataFrame, s::Union{Symbol, Vector{Symbol}}) = c.df[s]
Base.isequal(cs1::Vector{ChainDataFrame}, cs2::Vector{ChainDataFrame}) = isequal.(cs1, cs2)
Base.isequal(c1::ChainDataFrame, c2::ChainDataFrame) = isequal(c1, c2)

function Base.show(io::IO, cs::Vector{ChainDataFrame})
println(io, summary(cs))
Expand Down

0 comments on commit ad77a88

Please sign in to comment.