Skip to content

Commit

Permalink
Fix dimension ordering for traceplot with divergences (#2151)
Browse files Browse the repository at this point in the history
* Transpose diverging to expected order

* Add test for correct behavior

* Use correct keyword argument

* Add new Changelog headers

* Add changelog entry
  • Loading branch information
sethaxen authored Nov 1, 2022
1 parent d030d44 commit d9b75bb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Change Log

## v0.x.x Unreleased

### New features

### Maintenance and fixes
- Fix dimension ordering for `plot_trace` with divergences ([2151](https://github.com/arviz-devs/arviz/pull/2151))

### Deprecation

### Documentation

## v0.13.0 (2022 Oct 22)

### New features
Expand Down
4 changes: 3 additions & 1 deletion arviz/plots/traceplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ def plot_trace(
divergences = "top" if rug else "bottom"
if divergences:
try:
divergence_data = convert_to_dataset(data, group="sample_stats").diverging
divergence_data = convert_to_dataset(data, group="sample_stats").diverging.transpose(
"chain", "draw"
)
except (ValueError, AttributeError): # No sample_stats, or no `.diverging`
divergences = None

Expand Down
6 changes: 6 additions & 0 deletions arviz/tests/base_tests/test_plots_matplotlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ def test_plot_trace_invalid_varname_warning(models, kwargs):
assert axes.shape


def test_plot_trace_diverging_correctly_transposed():
idata = load_arviz_data("centered_eight")
idata.sample_stats["diverging"] = idata.sample_stats.diverging.T
plot_trace(idata, divergences="bottom")


@pytest.mark.parametrize(
"bad_kwargs", [{"var_names": ["mu", "tau"], "lines": [("mu", {}, ["hey"])]}]
)
Expand Down

0 comments on commit d9b75bb

Please sign in to comment.