Commit d7429366 authored by Gaetano Scandariato's avatar Gaetano Scandariato
Browse files

fix(reporting): replace mutable default argument in plot_corner (B006)

quantiles=[0.16, 0.5, 0.84] as a default argument is shared across
all calls. If the list were ever mutated (e.g. by a caller or by
corner.corner internally in a future version), all subsequent calls
using the default would receive the corrupted value.

Fix: use None as the sentinel and initialise inside the function body.
The behaviour is identical when callers omit the argument.
parent 0540cf06
Loading
Loading
Loading
Loading
Loading
+4 −2
Changes for PyAETNA/reporting/corner_plot.py: 4 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ def plot_corner(
    param_names=None,
    truths=None,
    title=None,
    quantiles=[0.16, 0.5, 0.84],
    quantiles=None,
    figsize=None,
    plModel=None,
    num_chains=1,
@@ -157,7 +157,7 @@ def plot_corner(
        param_names: Optional list of parameters to include
        truths: Optional dict of true/best-fit values
        title: Optional title for the plot
        quantiles: Quantiles to show on histograms
        quantiles: Quantiles to show on histograms. Defaults to [0.16, 0.5, 0.84].
        figsize: Optional figure size
        plModel: Optional PlModel object for renaming parameters with instrument names
        num_chains: Number of chains (required if discard_extra_warmup > 0)
@@ -166,6 +166,8 @@ def plot_corner(
    Returns:
        fig: matplotlib figure
    """
    if quantiles is None:
        quantiles = [0.16, 0.5, 0.84]

    # If extra warmup discard is requested, construct a temporary samples dict
    samples_for_corner = samples_dict