Skip to content

Fix plot_lm handling of multidimensional data with y_model #2408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 27, 2025

Conversation

uzairgheewala
Copy link
Contributor

@uzairgheewala uzairgheewala commented Jan 13, 2025

Description

Fix plot_lm functionality when using multidimensional data with y_model parameter. Previously, attempting to use plot_lm with both multidimensional y and y_model would result in dimension mismatch errors.
Also adds a test to check for the proper functioning of plot_lm when using multidimensional data with y_model parameter.
Addresses issue #1992.

Checklist

  • Follows official PR format
  • Includes a sample plot to visually illustrate the changes (only for plot-related functions)
  • Includes new or updated tests to cover the new feature
  • Code style correct (follows pylint and black guidelines)
  • Changes are listed in changelog

Following problematic cases in this notebook now work: https://gist.github.com/colehaus/b2aa195687f53ef7c86eec2ebb3798c2

  # Works now with multidimensional data
  data = az.from_dict(
      observed_data = { "y": np.random.normal(size=(5, 7)) },
      posterior = {"y_model": np.random.randn(4, 1000, 5, 7)},
      dims={"y": ["dim1", "dim2"]},
      coords={"dim1": range(5), "dim2": range(7)}
  )
  # Both modes now work
  az.plot_lm(idata=data, y="y", plot_dim="dim1", y_model="y_model", kind_model="lines")
  az.plot_lm(idata=data, y="y", plot_dim="dim1", y_model="y_model", kind_model="hdi")

📚 Documentation preview 📚: https://arviz--2408.org.readthedocs.build/en/2408/

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 98.11321% with 1 line in your changes missing coverage. Please review.

Project coverage is 86.84%. Comparing base (3205b82) to head (b421642).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
arviz/plots/backends/bokeh/hdiplot.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2408      +/-   ##
==========================================
+ Coverage   86.81%   86.84%   +0.02%     
==========================================
  Files         124      124              
  Lines       12972    13007      +35     
==========================================
+ Hits        11262    11296      +34     
- Misses       1710     1711       +1     

☔ View full report in Codecov by Sentry.
📢 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.

@OriolAbril OriolAbril changed the title Fix plot_lm handling of multidimensional data with y_model (#1992) Fix plot_lm handling of multidimensional data with y_model May 27, 2025
Copy link
Member

@OriolAbril OriolAbril left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

I did some changes to the tests so each test generates only one plot but the test cases are the same

@OriolAbril OriolAbril force-pushed the fix/plotlm-multidim-ymodel branch from 4fa79b7 to b421642 Compare May 27, 2025 20:06
@OriolAbril OriolAbril linked an issue May 27, 2025 that may be closed by this pull request
@OriolAbril OriolAbril merged commit 2e4cfcf into arviz-devs:main May 27, 2025
12 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.

plot_lm doesn't work with y_model and multidimensional y
2 participants