@@ -34,7 +34,7 @@
Loading
34 34
convert_result(::typeof(waic), result) = todataframes(result)
35 35
convert_result(::typeof(r2_score), result) = todataframes(result)
36 36
function convert_result(::typeof(compare), result)
37 -
    return todataframes(result; index_name = :name)
37 +
    return todataframes(result; index_name=:name)
38 38
end
39 39
40 40
@doc doc"""
@@ -126,15 +126,15 @@
Loading
126 126
summarystats(idata; var_names = ["mu", "tau"], stat_funcs = func_dict, extend = false)
127 127
```
128 128
"""
129 -
function StatsBase.summarystats(data::InferenceData; group = :posterior, kwargs...)
129 +
function StatsBase.summarystats(data::InferenceData; group=:posterior, kwargs...)
130 130
    dataset = getproperty(data, Symbol(group))
131 131
    return summarystats(dataset; kwargs...)
132 132
end
133 -
function StatsBase.summarystats(data::Dataset; index_origin = 1, fmt = :wide, kwargs...)
134 -
    s = arviz.summary(data; index_origin = index_origin, fmt = fmt, kwargs...)
133 +
function StatsBase.summarystats(data::Dataset; index_origin=1, fmt=:wide, kwargs...)
134 +
    s = arviz.summary(data; index_origin=index_origin, fmt=fmt, kwargs...)
135 135
    s isa Dataset && return s
136 136
    index_name = Symbol(fmt) == :long ? :statistic : :variable
137 -
    return todataframes(s; index_name = index_name)
137 +
    return todataframes(s; index_name=index_name)
138 138
end
139 139
140 140
"""
@@ -150,12 +150,12 @@
Loading
150 150
151 151
# Keywords
152 152
153 -
- `coords::Dict{String,Vector}=nothing`: Map from named dimension to named indices.
154 -
- `dims::Dict{String,Vector{String}}=nothing`: Map from variable name to names of its
153 +
  - `coords::Dict{String,Vector}=nothing`: Map from named dimension to named indices.
154 +
  - `dims::Dict{String,Vector{String}}=nothing`: Map from variable name to names of its
155 155
    dimensions.
156 -
- `kwargs`: Keyword arguments passed to [`summarystats`](@ref).
156 +
  - `kwargs`: Keyword arguments passed to [`summarystats`](@ref).
157 157
"""
158 -
function summary(data; group = :posterior, coords = nothing, dims = nothing, kwargs...)
159 -
    dataset = convert_to_dataset(data; group = group, coords = coords, dims = dims)
158 +
function summary(data; group=:posterior, coords=nothing, dims=nothing, kwargs...)
159 +
    dataset = convert_to_dataset(data; group=group, coords=coords, dims=dims)
160 160
    return summarystats(dataset; kwargs...)
161 161
end

@@ -18,9 +18,10 @@
Loading
18 18
Convert `MonteCarloMeasurements.AbstractParticles` to an [`InferenceData`](@ref).
19 19
20 20
`obj` may have the following types:
21 -
- `::AbstractParticles`: Univariate draws from a single chain.
22 -
- `::AbstractVector{<:AbstractParticles}`: Univariate draws from a vector of chains.
23 -
- `::AbstractVector{<:AbstractArray{<:AbstractParticles}}`: Multivariate draws from a vector
21 +
22 +
  - `::AbstractParticles`: Univariate draws from a single chain.
23 +
  - `::AbstractVector{<:AbstractParticles}`: Univariate draws from a vector of chains.
24 +
  - `::AbstractVector{<:AbstractArray{<:AbstractParticles}}`: Multivariate draws from a vector
24 25
    of chains.
25 26
"""
26 27
function convert_to_inference_data(obj::AbstractParticles; kwargs...)
@@ -30,8 +31,7 @@
Loading
30 31
    return convert_to_inference_data(stack(stack.(obj)); kwargs...)
31 32
end
32 33
function convert_to_inference_data(
33 -
    obj::AbstractVector{<:AbstractArray{<:AbstractParticles}};
34 -
    kwargs...,
34 +
    obj::AbstractVector{<:AbstractArray{<:AbstractParticles}}; kwargs...
35 35
)
36 36
    return convert_to_inference_data(stack(stack.(obj)); kwargs...)
37 37
end

@@ -96,7 +96,7 @@
Loading
96 96
97 97
# Load ArviZ once at precompilation time for docstringS
98 98
copy!(arviz, import_arviz())
99 -
check_needs_update(update = false)
99 +
check_needs_update(; update=false)
100 100
const _precompile_arviz_version = arviz_version()
101 101
102 102
function __init__()

@@ -1,9 +1,9 @@
Loading
1 1
const has_bokeh_png_deps = false
2 2
3 3
function initialize_bokeh()
4 -
    ispynull(bokeh) || return
4 +
    ispynull(bokeh) || return nothing
5 5
    try
6 -
        copy!(bokeh, _import_dependency("bokeh", "bokeh"; channel = "conda-forge"))
6 +
        copy!(bokeh, _import_dependency("bokeh", "bokeh"; channel="conda-forge"))
7 7
    catch err
8 8
        copy!(bokeh, PyNULL())
9 9
        throw(err)
@@ -13,9 +13,9 @@
Loading
13 13
14 14
# install dependencies for saving PNGs if using conda
15 15
function initialize_bokeh_png_deps()
16 -
    has_bokeh_png_deps && return
16 +
    has_bokeh_png_deps && return nothing
17 17
    try
18 -
        _import_dependency("selenium", "selenium"; channel = "conda-forge")
18 +
        _import_dependency("selenium", "selenium"; channel="conda-forge")
19 19
        has_bokeh_png_deps = true
20 20
    catch err
21 21
        has_bokeh_png_deps = false
@@ -59,7 +59,7 @@
Loading
59 59
    return getproperty(o, name)
60 60
end
61 61
62 -
function render_html(plot::BokehPlot, name = nothing)
62 +
function render_html(plot::BokehPlot, name=nothing)
63 63
    obj = PyObject(plot)
64 64
    return bokeh.embed.file_html(obj, bokeh.resources.CDN, name)
65 65
end

@@ -5,7 +5,7 @@
Loading
5 5
@forwardfun rhat
6 6
7 7
function convert_arguments(::typeof(bfmi), data, args...; kwargs...)
8 -
    dataset = convert_to_dataset(data; group = :sample_stats)
8 +
    dataset = convert_to_dataset(data; group=:sample_stats)
9 9
    return tuple(dataset, args...), kwargs
10 10
end
11 11
function convert_arguments(::typeof(bfmi), data::AbstractArray, args...; kwargs...)
@@ -15,7 +15,7 @@
Loading
15 15
for f in (:ess, :mcse, :rhat)
16 16
    @eval begin
17 17
        function convert_arguments(::typeof($(f)), data, args...; kwargs...)
18 -
            dataset = convert_to_dataset(data; group = :posterior)
18 +
            dataset = convert_to_dataset(data; group=:posterior)
19 19
            return tuple(dataset, args...), kwargs
20 20
        end
21 21
        function convert_arguments(::typeof($(f)), data::AbstractArray, args...; kwargs...)

@@ -11,7 +11,7 @@
Loading
11 11
```@example
12 12
using ArviZ
13 13
nchains, ndraws = 4, 100
14 -
data = [(x = rand(), y = randn(2), z = randn(2, 3)) for _ in 1:nchains, _ in 1:ndraws];
14 +
data = [(x=rand(), y=randn(2), z=randn(2, 3)) for _ in 1:nchains, _ in 1:ndraws];
15 15
stacked_data = ArviZ.stack(data);
16 16
```
17 17
"""
@@ -27,7 +27,7 @@
Loading
27 27
    return ret
28 28
end
29 29
function stack(x::AbstractArray{<:NamedTuple{K}}) where {K}
30 -
    length(x) == 0 && return
30 +
    length(x) == 0 && return nothing
31 31
    @inbounds x1 = x[1]
32 32
    ret = NamedTuple()
33 33
    for k in K
@@ -127,7 +127,7 @@
Loading
127 127
    sample_stats,
128 128
    predictions,
129 129
    log_likelihood;
130 -
    library = nothing,
130 +
    library=nothing,
131 131
    kwargs...,
132 132
)
133 133
    all_idata = InferenceData()
@@ -161,23 +161,23 @@
Loading
161 161
    if library !== nothing
162 162
        setattribute!(group_dataset, "inference_library", string(library))
163 163
    end
164 -
    concat!(all_idata, InferenceData(posterior = group_dataset))
164 +
    concat!(all_idata, InferenceData(; posterior=group_dataset))
165 165
166 166
    return all_idata
167 167
end
168 168
function from_namedtuple(
169 -
    posterior::Union{NamedTuple,Nothing} = nothing;
170 -
    posterior_predictive = nothing,
171 -
    sample_stats = nothing,
172 -
    predictions = nothing,
173 -
    prior = nothing,
174 -
    prior_predictive = nothing,
175 -
    sample_stats_prior = nothing,
176 -
    observed_data = nothing,
177 -
    constant_data = nothing,
178 -
    predictions_constant_data = nothing,
179 -
    log_likelihood = nothing,
180 -
    library = nothing,
169 +
    posterior::Union{NamedTuple,Nothing}=nothing;
170 +
    posterior_predictive=nothing,
171 +
    sample_stats=nothing,
172 +
    predictions=nothing,
173 +
    prior=nothing,
174 +
    prior_predictive=nothing,
175 +
    sample_stats_prior=nothing,
176 +
    observed_data=nothing,
177 +
    constant_data=nothing,
178 +
    predictions_constant_data=nothing,
179 +
    log_likelihood=nothing,
180 +
    library=nothing,
181 181
    kwargs...,
182 182
)
183 183
    all_idata = from_namedtuple(
@@ -186,16 +186,16 @@
Loading
186 186
        sample_stats,
187 187
        predictions,
188 188
        log_likelihood;
189 -
        library = library,
189 +
        library=library,
190 190
        kwargs...,
191 191
    )
192 192
193 193
    if any(x -> x !== nothing, [prior, prior_predictive, sample_stats_prior])
194 194
        pre_prior_idata = convert_to_inference_data(
195 195
            prior;
196 -
            posterior_predictive = prior_predictive,
197 -
            sample_stats = sample_stats_prior,
198 -
            library = library,
196 +
            posterior_predictive=prior_predictive,
197 +
            sample_stats=sample_stats_prior,
198 +
            library=library,
199 199
            kwargs...,
200 200
        )
201 201
        prior_idata = rekey(
@@ -216,8 +216,7 @@
Loading
216 216
    ]
217 217
        group_data === nothing && continue
218 218
        group_dict = convert(Dict, group_data)
219 -
        group_dataset =
220 -
            convert_to_constant_dataset(group_dict; library = library, kwargs...)
219 +
        group_dataset = convert_to_constant_dataset(group_dict; library=library, kwargs...)
221 220
        concat!(all_idata, InferenceData(; group => group_dataset))
222 221
    end
223 222
@@ -250,8 +249,7 @@
Loading
250 249
    return from_namedtuple(data; kwargs...)
251 250
end
252 251
function convert_to_inference_data(
253 -
    data::AbstractVector{<:AbstractVector{<:NamedTuple}};
254 -
    kwargs...,
252 +
    data::AbstractVector{<:AbstractVector{<:NamedTuple}}; kwargs...
255 253
)
256 254
    return from_namedtuple(data; kwargs...)
257 255
end

@@ -17,7 +17,7 @@
Loading
17 17
"""
18 18
with_interactive_backend
19 19
20 -
function with_interactive_backend(f; backend = nothing)
20 +
function with_interactive_backend(f; backend=nothing)
21 21
    oldisint = PyPlot.isinteractive()
22 22
    oldgui = pygui()
23 23
    backend === nothing || pygui(Symbol(backend))
@@ -90,17 +90,19 @@
Loading
90 90
"""
91 91
macro forwardfun(f)
92 92
    fdoc = forwarddoc(f)
93 -
    return esc(quote
94 -
        @doc $fdoc $f
95 -
96 -
        function $(f)(args...; kwargs...)
97 -
            args, kwargs = convert_arguments($(f), args...; kwargs...)
98 -
            result = arviz.$(f)(args...; kwargs...)
99 -
            return convert_result($(f), result)
100 -
        end
93 +
    return esc(
94 +
        quote
95 +
            @doc $fdoc $f
96 +
97 +
            function $(f)(args...; kwargs...)
98 +
                args, kwargs = convert_arguments($(f), args...; kwargs...)
99 +
                result = arviz.$(f)(args...; kwargs...)
100 +
                return convert_result($(f), result)
101 +
            end
101 102
102 -
        Docs.getdoc(::typeof($(f))) = forwardgetdoc(Symbol($(f)))
103 -
    end)
103 +
            Docs.getdoc(::typeof($(f))) = forwardgetdoc(Symbol($(f)))
104 +
        end,
105 +
    )
104 106
end
105 107
106 108
"""
@@ -115,23 +117,25 @@
Loading
115 117
"""
116 118
macro forwardplotfun(f)
117 119
    fdoc = forwarddoc(f)
118 -
    return esc(quote
119 -
        @doc $fdoc $f
120 -
121 -
        function $(f)(args...; backend = nothing, kwargs...)
122 -
            if backend === nothing
123 -
                backend = get(rcParams, "plot.backend", nothing)
120 +
    return esc(
121 +
        quote
122 +
            @doc $fdoc $f
123 +
124 +
            function $(f)(args...; backend=nothing, kwargs...)
125 +
                if backend === nothing
126 +
                    backend = get(rcParams, "plot.backend", nothing)
127 +
                end
128 +
                backend = Symbol(backend)
129 +
                backend_val = Val(backend)
130 +
                load_backend(backend_val)
131 +
                args, kwargs = convert_arguments($(f), args...; kwargs...)
132 +
                result = arviz.$(f)(args...; kwargs..., backend=backend)
133 +
                return convert_result($(f), result, backend_val)
124 134
            end
125 -
            backend = Symbol(backend)
126 -
            backend_val = Val(backend)
127 -
            load_backend(backend_val)
128 -
            args, kwargs = convert_arguments($(f), args...; kwargs...)
129 -
            result = arviz.$(f)(args...; kwargs..., backend = backend)
130 -
            return convert_result($(f), result, backend_val)
131 -
        end
132 -
133 -
        Docs.getdoc(::typeof($(f))) = forwardgetdoc(Symbol($(f)))
134 -
    end)
135 +
136 +
            Docs.getdoc(::typeof($(f))) = forwardgetdoc(Symbol($(f)))
137 +
        end,
138 +
    )
135 139
end
136 140
137 141
# Replace `missing` values with `NaN` and do type inference on the result
@@ -192,7 +196,7 @@
Loading
192 196
If `index_name` is not `nothing`, the index is converted into a column with `index_name`.
193 197
Otherwise, it is discarded.
194 198
"""
195 -
function todataframes(::Val{:DataFrame}, df::PyObject; index_name = nothing)
199 +
function todataframes(::Val{:DataFrame}, df::PyObject; index_name=nothing)
196 200
    initialize_pandas()
197 201
    col_vals = map(df.columns) do name
198 202
        series = py"$(df)[$(name)]"
@@ -229,13 +233,13 @@
Loading
229 233
If `index_name` is not `nothing`, the corresponding column is made the index of the
230 234
returned dataframe.
231 235
"""
232 -
function topandas(::Val{:DataFrame}, df; index_name = nothing)
236 +
function topandas(::Val{:DataFrame}, df; index_name=nothing)
233 237
    initialize_pandas()
234 238
    df = DataFrames.DataFrame(df)
235 239
    colnames = names(df)
236 240
    rowvals = map(Array, eachrow(df))
237 -
    pdf = pandas.DataFrame(rowvals; columns = colnames)
238 -
    index_name !== nothing && pdf.set_index(index_name; inplace = true)
241 +
    pdf = pandas.DataFrame(rowvals; columns=colnames)
242 +
    index_name !== nothing && pdf.set_index(index_name; inplace=true)
239 243
    return pdf
240 244
end
241 245
function topandas(::Val{:Series}, df)

@@ -44,7 +44,11 @@
Loading
44 44
            if pyisinstance(err, py"ValueError")
45 45
                throw(ErrorException(err.args[1]))
46 46
            elseif pyisinstance(err, py"KeyError")
47 -
                throw(KeyError("$(k) is not a valid rc parameter (see keys(rcParams) for a list of valid parameters)"))
47 +
                throw(
48 +
                    KeyError(
49 +
                        "$(k) is not a valid rc parameter (see keys(rcParams) for a list of valid parameters)",
50 +
                    ),
51 +
                )
48 52
            end
49 53
        end
50 54
        throw(e)

@@ -63,19 +63,20 @@
Loading
63 63
    ndraws, _, nchains = size(chns)
64 64
    loc_names_old = getfield(chns.name_map, section) # old may be Symbol or String
65 65
    loc_names = string.(loc_names_old)
66 -
    loc_str_to_old =
67 -
        Dict(name_str => name_old for (name_str, name_old) in zip(loc_names, loc_names_old))
66 +
    loc_str_to_old = Dict(
67 +
        name_str => name_old for (name_str, name_old) in zip(loc_names, loc_names_old)
68 +
    )
68 69
    vars_to_locs = varnames_locs_dict(loc_names, loc_str_to_old)
69 70
    vars_to_arrays = Dict{String,Array}()
70 71
    for (var_name, names_locs) in vars_to_locs
71 72
        loc_names, locs = names_locs
72 -
        max_loc = maximum(hcat([[loc...] for loc in locs]...); dims = 2)
73 +
        max_loc = maximum(hcat([[loc...] for loc in locs]...); dims=2)
73 74
        ndim = length(max_loc)
74 75
        sizes = tuple(max_loc...)
75 76
76 77
        oldarr = reshape_values(replacemissing(Array(chns.value[:, loc_names, :])))
77 78
        if ndim == 0
78 -
            arr = dropdims(oldarr; dims = 3)
79 +
            arr = dropdims(oldarr; dims=3)
79 80
        else
80 81
            arr = Array{Union{typeof(NaN),eltype(oldarr)}}(undef, nchains, ndraws, sizes...)
81 82
            fill!(arr, NaN)
@@ -89,10 +90,7 @@
Loading
89 90
end
90 91
91 92
function chains_to_dict(
92 -
    chns::Chains;
93 -
    ignore = String[],
94 -
    section = :parameters,
95 -
    rekey_fun = identity,
93 +
    chns::Chains; ignore=String[], section=:parameters, rekey_fun=identity
96 94
)
97 95
    section in sections(chns) || return Dict()
98 96
    chns_dict = section_dict(chns, section)
@@ -108,7 +106,7 @@
Loading
108 106
109 107
Remaining `kwargs` are forwarded to [`from_mcmcchains`](@ref).
110 108
"""
111 -
function convert_to_inference_data(chns::Chains; group = :posterior, kwargs...)
109 +
function convert_to_inference_data(chns::Chains; group=:posterior, kwargs...)
112 110
    group = Symbol(group)
113 111
    group == :posterior && return from_mcmcchains(chns; kwargs...)
114 112
    return from_mcmcchains(; group => chns)
@@ -169,16 +167,16 @@
Loading
169 167
    posterior_predictive,
170 168
    predictions,
171 169
    log_likelihood;
172 -
    library = MCMCChains,
170 +
    library=MCMCChains,
173 171
    kwargs...,
174 172
)
175 -
    kwargs = convert(Dict, merge((; dims = nothing), kwargs))
173 +
    kwargs = convert(Dict, merge((; dims=nothing), kwargs))
176 174
    library = string(library)
177 175
    rekey_fun = d -> rekey(d, stats_key_map)
178 176
179 177
    # Convert chains to dicts
180 178
    post_dict = chains_to_dict(posterior)
181 -
    stats_dict = chains_to_dict(posterior; section = :internals, rekey_fun = rekey_fun)
179 +
    stats_dict = chains_to_dict(posterior; section=:internals, rekey_fun=rekey_fun)
182 180
    stats_dict = enforce_stat_types(stats_dict)
183 181
184 182
    all_idata = InferenceData()
@@ -197,48 +195,45 @@
Loading
197 195
        if group_data isa Union{AbstractVector{String},NTuple{N,String} where {N}}
198 196
            group_data = popsubdict!(post_dict, group_data)
199 197
        end
200 -
        group_dataset = convert_to_dataset(group_data; library = library, kwargs...)
198 +
        group_dataset = convert_to_dataset(group_data; library=library, kwargs...)
201 199
        setattribute!(group_dataset, "inference_library", library)
202 200
        concat!(all_idata, InferenceData(; group => group_dataset))
203 201
    end
204 202
205 203
    attrs = attributes_dict(posterior)
206 204
    attrs = merge(attrs, Dict("inference_library" => library))
207 -
    kwargs = convert(Dict, merge((; attrs = attrs, dims = nothing), kwargs))
208 -
    post_idata = _from_dict(post_dict; sample_stats = stats_dict, kwargs...)
205 +
    kwargs = convert(Dict, merge((; attrs=attrs, dims=nothing), kwargs))
206 +
    post_idata = _from_dict(post_dict; sample_stats=stats_dict, kwargs...)
209 207
    concat!(all_idata, post_idata)
210 208
    return all_idata
211 209
end
212 210
function from_mcmcchains(
213 -
    posterior = nothing;
214 -
    posterior_predictive = nothing,
215 -
    predictions = nothing,
216 -
    prior = nothing,
217 -
    prior_predictive = nothing,
218 -
    observed_data = nothing,
219 -
    constant_data = nothing,
220 -
    predictions_constant_data = nothing,
221 -
    log_likelihood = nothing,
222 -
    library = MCMCChains,
211 +
    posterior=nothing;
212 +
    posterior_predictive=nothing,
213 +
    predictions=nothing,
214 +
    prior=nothing,
215 +
    prior_predictive=nothing,
216 +
    observed_data=nothing,
217 +
    constant_data=nothing,
218 +
    predictions_constant_data=nothing,
219 +
    log_likelihood=nothing,
220 +
    library=MCMCChains,
223 221
    kwargs...,
224 222
)
225 -
    kwargs = convert(Dict, merge((; dims = nothing, coords = nothing), kwargs))
223 +
    kwargs = convert(Dict, merge((; dims=nothing, coords=nothing), kwargs))
226 224
227 225
    all_idata = from_mcmcchains(
228 226
        posterior,
229 227
        posterior_predictive,
230 228
        predictions,
231 229
        log_likelihood;
232 -
        library = library,
230 +
        library=library,
233 231
        kwargs...,
234 232
    )
235 233
236 234
    if prior !== nothing
237 235
        pre_prior_idata = convert_to_inference_data(
238 -
            prior;
239 -
            posterior_predictive = prior_predictive,
240 -
            library = library,
241 -
            kwargs...,
236 +
            prior; posterior_predictive=prior_predictive, library=library, kwargs...
242 237
        )
243 238
        prior_idata = rekey(
244 239
            pre_prior_idata,
@@ -257,8 +252,7 @@
Loading
257 252
        :predictions_constant_data => predictions_constant_data,
258 253
    ]
259 254
        group_data === nothing && continue
260 -
        group_dataset =
261 -
            convert_to_constant_dataset(group_data; library = library, kwargs...)
255 +
        group_dataset = convert_to_constant_dataset(group_data; library=library, kwargs...)
262 256
        concat!(all_idata, InferenceData(; group => group_dataset))
263 257
    end
264 258
@@ -271,5 +265,5 @@
Loading
271 265
Call [`from_mcmcchains`](@ref) on output of `CmdStan`.
272 266
"""
273 267
function from_cmdstan(posterior::Chains; kwargs...)
274 -
    return from_mcmcchains(posterior; library = "CmdStan", kwargs...)
268 +
    return from_mcmcchains(posterior; library="CmdStan", kwargs...)
275 269
end

@@ -6,13 +6,15 @@
Loading
6 6
7 7
# Keywords
8 8
9 -
- `data_vars::Dict{String,Any}`: Dict mapping variable names to
10 -
    + `Vector`: Data vector. Single dimension is named after variable.
11 -
    + `Tuple{String,Vector}`: Dimension name and data vector.
12 -
    + `Tuple{NTuple{N,String},Array{T,N}} where {N,T}`: Dimension names and data array.
13 -
- `coords::Dict{String,Any}`: Dict mapping dimension names to index names. Possible
9 +
  - `data_vars::Dict{String,Any}`: Dict mapping variable names to
10 +
    
11 +
      + `Vector`: Data vector. Single dimension is named after variable.
12 +
      + `Tuple{String,Vector}`: Dimension name and data vector.
13 +
      + `Tuple{NTuple{N,String},Array{T,N}} where {N,T}`: Dimension names and data array.
14 +
15 +
  - `coords::Dict{String,Any}`: Dict mapping dimension names to index names. Possible
14 16
    arguments has same form as `data_vars`.
15 -
- `attrs::Dict{String,Any}`: Global attributes to save on this dataset.
17 +
  - `attrs::Dict{String,Any}`: Global attributes to save on this dataset.
16 18
17 19
In most cases, use [`convert_to_dataset`](@ref) or [`convert_to_constant_dataset`](@ref) or
18 20
to create a `Dataset` instead of directly using a constructor.
@@ -82,9 +84,9 @@
Loading
82 84
"""
83 85
convert_to_dataset
84 86
85 -
function convert_to_dataset(obj; group = :posterior, kwargs...)
87 +
function convert_to_dataset(obj; group=:posterior, kwargs...)
86 88
    group = Symbol(group)
87 -
    idata = convert_to_inference_data(obj; group = group, kwargs...)
89 +
    idata = convert_to_inference_data(obj; group=group, kwargs...)
88 90
    dataset = getproperty(idata, group)
89 91
    return dataset
90 92
end
@@ -110,11 +112,7 @@
Loading
110 112
convert_to_constant_dataset
111 113
112 114
function convert_to_constant_dataset(
113 -
    obj;
114 -
    coords = nothing,
115 -
    dims = nothing,
116 -
    library = nothing,
117 -
    attrs = nothing,
115 +
    obj; coords=nothing, dims=nothing, library=nothing, attrs=nothing
118 116
)
119 117
    base = arviz.data.base
120 118
@@ -127,9 +125,10 @@
Loading
127 125
    for (key, vals) in obj
128 126
        vals = _asarray(vals)
129 127
        val_dims = get(dims, key, nothing)
130 -
        (val_dims, val_coords) =
131 -
            base.generate_dims_coords(size(vals), key; dims = val_dims, coords = coords)
132 -
        data[key] = xarray.DataArray(vals; dims = val_dims, coords = val_coords)
128 +
        (val_dims, val_coords) = base.generate_dims_coords(
129 +
            size(vals), key; dims=val_dims, coords=coords
130 +
        )
131 +
        data[key] = xarray.DataArray(vals; dims=val_dims, coords=val_coords)
133 132
    end
134 133
135 134
    default_attrs = base.make_attrs()
@@ -137,7 +136,7 @@
Loading
137 136
        default_attrs = merge(default_attrs, Dict("inference_library" => string(library)))
138 137
    end
139 138
    attrs = merge(default_attrs, attrs)
140 -
    return Dataset(data_vars = data, coords = coords, attrs = attrs)
139 +
    return Dataset(; data_vars=data, coords=coords, attrs=attrs)
141 140
end
142 141
143 142
@doc doc"""
@@ -164,12 +163,12 @@
Loading
164 163
"""
165 164
dict_to_dataset
166 165
167 -
function dict_to_dataset(data; library = nothing, attrs = nothing, kwargs...)
166 +
function dict_to_dataset(data; library=nothing, attrs=nothing, kwargs...)
168 167
    if library !== nothing
169 168
        ldict = Dict("inference_library" => string(library))
170 169
        attrs = (attrs === nothing ? ldict : merge(attrs, ldict))
171 170
    end
172 -
    return arviz.dict_to_dataset(data; attrs = attrs, kwargs...)
171 +
    return arviz.dict_to_dataset(data; attrs=attrs, kwargs...)
173 172
end
174 173
175 174
@doc doc"""
@@ -200,5 +199,5 @@
Loading
200 199
        end
201 200
    end
202 201
203 -
    return data, (attrs = attrs, coords = coords, dims = dims)
202 +
    return data, (attrs=attrs, coords=coords, dims=dims)
204 203
end

@@ -87,7 +87,7 @@
Loading
87 87
88 88
convert_to_inference_data(::Nothing; kwargs...) = InferenceData()
89 89
90 -
function convert_to_dataset(data::InferenceData; group = :posterior, kwargs...)
90 +
function convert_to_dataset(data::InferenceData; group=:posterior, kwargs...)
91 91
    group = Symbol(group)
92 92
    dataset = getproperty(data, group)
93 93
    return dataset
@@ -109,19 +109,13 @@
Loading
109 109
110 110
# A more flexible form of `from_dict`
111 111
# Internally calls `dict_to_dataset`
112 -
function _from_dict(
113 -
    posterior = nothing;
114 -
    attrs = Dict(),
115 -
    coords = nothing,
116 -
    dims = nothing,
117 -
    dicts...,
118 -
)
119 -
    dicts = (posterior = posterior, dicts...)
112 +
function _from_dict(posterior=nothing; attrs=Dict(), coords=nothing, dims=nothing, dicts...)
113 +
    dicts = (posterior=posterior, dicts...)
120 114
121 115
    datasets = []
122 116
    for (name, dict) in pairs(dicts)
123 117
        (dict === nothing || isempty(dict)) && continue
124 -
        dataset = dict_to_dataset(dict; attrs = attrs, coords = coords, dims = dims)
118 +
        dataset = dict_to_dataset(dict; attrs=attrs, coords=coords, dims=dims)
125 119
        push!(datasets, name => dataset)
126 120
    end
127 121
@@ -132,7 +126,7 @@
Loading
132 126
@doc forwarddoc(:concat) concat
133 127
134 128
function concat(data::InferenceData...; kwargs...)
135 -
    return arviz.concat(data...; inplace = false, kwargs...)
129 +
    return arviz.concat(data...; inplace=false, kwargs...)
136 130
end
137 131
138 132
Docs.getdoc(::typeof(concat)) = forwardgetdoc(:concat)
@@ -146,7 +140,7 @@
Loading
146 140
concat!
147 141
148 142
function concat!(data::InferenceData, other_data::InferenceData...; kwargs...)
149 -
    arviz.concat(data, other_data...; inplace = true, kwargs...)
143 +
    arviz.concat(data, other_data...; inplace=true, kwargs...)
150 144
    return data
151 145
end
152 146
concat!(; kwargs...) = InferenceData()
@@ -162,7 +156,7 @@
Loading
162 156
    return concat(data_new...)
163 157
end
164 158
165 -
function reorder_groups!(data::InferenceData; group_order = SUPPORTED_GROUPS)
159 +
function reorder_groups!(data::InferenceData; group_order=SUPPORTED_GROUPS)
166 160
    group_order = map(Symbol, group_order)
167 161
    names = groupnames(data)
168 162
    sorted_names = filter(n -> n ∈ names, group_order)

@@ -26,7 +26,7 @@
Loading
26 26
@deprecate plot_joint(args...; kwargs...) plot_pair(args...; kwargs...)
27 27
28 28
function convert_arguments(::typeof(plot_compare), df, args...; kwargs...)
29 -
    pdf = topandas(Val(:DataFrame), df; index_name = :name)
29 +
    pdf = topandas(Val(:DataFrame), df; index_name=:name)
30 30
    return tuple(pdf, args...), kwargs
31 31
end
32 32
@@ -54,7 +54,7 @@
Loading
54 54
)
55 55
    @eval begin
56 56
        function convert_arguments(::typeof($(f)), data, args...; kwargs...)
57 -
            idata = convert_to_inference_data(data; group = :posterior)
57 +
            idata = convert_to_inference_data(data; group=:posterior)
58 58
            return tuple(idata, args...), kwargs
59 59
        end
60 60
    end
@@ -69,22 +69,17 @@
Loading
69 69
end
70 70
71 71
function convert_arguments(::typeof(plot_energy), data, args...; kwargs...)
72 -
    dataset = convert_to_dataset(data; group = :sample_stats)
72 +
    dataset = convert_to_dataset(data; group=:sample_stats)
73 73
    return tuple(dataset, args...), kwargs
74 74
end
75 75
76 76
for f in (:plot_density, :plot_forest, :plot_rank)
77 77
    @eval begin
78 78
        function convert_arguments(
79 -
            ::typeof($(f)),
80 -
            data,
81 -
            args...;
82 -
            transform = identity,
83 -
            group = :posterior,
84 -
            kwargs...,
79 +
            ::typeof($(f)), data, args...; transform=identity, group=:posterior, kwargs...
85 80
        )
86 81
            tdata = transform(data)
87 -
            dataset = convert_to_dataset(tdata; group = group)
82 +
            dataset = convert_to_dataset(tdata; group=group)
88 83
            return tuple(dataset, args...), kwargs
89 84
        end
90 85
    end
@@ -95,27 +90,27 @@
Loading
95 90
        function convert_arguments(
96 91
            ::typeof($(f)),
97 92
            data::Union{AbstractVector,Tuple},
98 -
            transform = identity,
99 -
            group = :posterior,
93 +
            transform=identity,
94 +
            group=:posterior,
100 95
            args...;
101 96
            kwargs...,
102 97
        )
103 98
            tdata = transform(data)
104 99
            datasets = map(tdata) do datum
105 -
                return convert_to_dataset(datum; group = group)
100 +
                return convert_to_dataset(datum; group=group)
106 101
            end
107 102
            return tuple(datasets, args...), kwargs
108 103
        end
109 104
        function convert_arguments(
110 105
            ::typeof($(f)),
111 106
            data::AbstractVector{<:Real},
112 -
            transform = identity,
113 -
            group = :posterior,
107 +
            transform=identity,
108 +
            group=:posterior,
114 109
            args...;
115 110
            kwargs...,
116 111
        )
117 112
            tdata = transform(data)
118 -
            dataset = convert_to_dataset(tdata; group = group)
113 +
            dataset = convert_to_dataset(tdata; group=group)
119 114
            return tuple(dataset, args...), kwargs
120 115
        end
121 116
    end

@@ -1,8 +1,8 @@
Loading
1 -
import_arviz() = _import_dependency("arviz", "arviz"; channel = "conda-forge")
1 +
import_arviz() = _import_dependency("arviz", "arviz"; channel="conda-forge")
2 2
3 3
arviz_version() = VersionNumber(arviz.__version__)
4 4
5 -
function check_needs_update(; update = true)
5 +
function check_needs_update(; update=true)
6 6
    if arviz_version() < _min_arviz_version
7 7
        @warn "ArviZ.jl only officially supports arviz version $(_min_arviz_version) or " *
8 8
              "greater but found version $(arviz_version())."
@@ -39,9 +39,9 @@
Loading
39 39
end
40 40
41 41
function initialize_arviz()
42 -
    ispynull(arviz) || return
42 +
    ispynull(arviz) || return nothing
43 43
    copy!(arviz, import_arviz())
44 -
    check_needs_update(update = true)
44 +
    check_needs_update(; update=true)
45 45
    check_needs_rebuild()
46 46
47 47
    append!(SUPPORTED_GROUPS, map(Symbol, arviz.data.inference_data.SUPPORTED_GROUPS))
@@ -63,9 +63,9 @@
Loading
63 63
end
64 64
65 65
function initialize_xarray()
66 -
    ispynull(xarray) || return
67 -
    copy!(xarray, _import_dependency("xarray", "xarray"; channel = "conda-forge"))
68 -
    _import_dependency("dask", "dask"; channel = "conda-forge")
66 +
    ispynull(xarray) || return nothing
67 +
    copy!(xarray, _import_dependency("xarray", "xarray"; channel="conda-forge"))
68 +
    _import_dependency("dask", "dask"; channel="conda-forge")
69 69
    pytype_mapping(xarray.Dataset, Dataset)
70 70
    return nothing
71 71
end
@@ -77,8 +77,8 @@
Loading
77 77
end
78 78
79 79
function initialize_pandas()
80 -
    ispynull(pandas) || return
81 -
    copy!(pandas, _import_dependency("pandas", "pandas"; channel = "conda-forge"))
80 +
    ispynull(pandas) || return nothing
81 +
    copy!(pandas, _import_dependency("pandas", "pandas"; channel="conda-forge"))
82 82
    return nothing
83 83
end
84 84
@@ -87,7 +87,7 @@
Loading
87 87
    if _using_conda() && _isyes(Base.prompt("Try updating arviz using conda? [Y/n]"))
88 88
        # this syntax isn't officially supported, but it works (for now)
89 89
        try
90 -
            Conda.add("arviz>=$_min_arviz_version"; channel = "conda-forge")
90 +
            Conda.add("arviz>=$_min_arviz_version"; channel="conda-forge")
91 91
            return true
92 92
        catch e
93 93
            println(e.msg)
@@ -105,7 +105,7 @@
Loading
105 105
    return false
106 106
end
107 107
108 -
function _import_dependency(modulename, pkgname = modulename; channel = nothing)
108 +
function _import_dependency(modulename, pkgname=modulename; channel=nothing)
109 109
    try
110 110
        return if channel === nothing
111 111
            pyimport_conda(modulename, pkgname)
Files Coverage
src 88.50%
Project Totals (13 files) 88.50%
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading