Skip to content

Reduce MAD over sample_dims in summary median kinds - #496

Merged
aloctavodia merged 2 commits into
arviz-devs:mainfrom
cristianchiriac:summary-mad-sample-dims
Oct 20, 2026
Merged

aloctavodia merged 2 commits into
arviz-devs:mainfrom
cristianchiriac:summary-mad-sample-dims

Conversation

@cristianchiriac

Copy link
Copy Markdown
Contributor

Fixes #492.

summary(kind="stats_median") and kind="all_median" computed the MAD with stats.median_abs_deviation(dataset, dims=("chain", "draw"), ...), while the median and the ETI next to it reduce over sample_dims. With sample_dims=["draw"], each chain got the MAD pooled over all chains. The MAD now uses dims=validate_dims(sample_dims), like the rest of the function.

Tests in tests/test_summary.py, using the dataset from the issue (2 chains × 4 draws):

  • test_summary_stats_median_reduces_mad_over_sample_dims with sample_dims="draw" and ["draw"]: median [1.5, 103.0] and MAD [1.0, 2.0]. Before the change, the MAD was [50.5, 50.5].
  • test_summary_median_kind_pools_mad_by_default: the default call still gives the pooled MAD [50.5].

all_median goes through the same line, but it can't run with sample_dims=["draw"] because the diagnostics (r_hat) need two dims, so the test uses stats_median.

ruff check and ruff format --check are clean. In tests/test_summary.py on my machine, test_summary_data_frame, test_rope_coords, test_ci_in_rope_default_ci_kind and test_summary_sd_uses_sample_std fail or error the same way with and without this change (missing test-xarray extras locally). Everything else passes.

summary(kind="stats_median" or "all_median") computed the MAD over a
hardcoded ("chain", "draw"), while the median and eti use sample_dims,
so with sample_dims=["draw"] it reported the pooled MAD for every chain.

Fixes #492
@read-the-docs-community

read-the-docs-community Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Comment thread tests/test_summary.py Outdated
Co-authored-by: Osvaldo A Martin <aloctavodia@gmail.com>
@codecov-commenter

codecov-commenter commented Oct 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.75%. Comparing base (90b594d) to head (15eb6be).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #496      +/-   ##
==========================================
+ Coverage   84.63%   84.75%   +0.11%     
==========================================
  Files          48       49       +1     
  Lines        6978     7111     +133     
==========================================
+ Hits         5906     6027     +121     
- Misses       1072     1084      +12     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aloctavodia
aloctavodia merged commit 0302ddc into arviz-devs:main Oct 20, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants