Skip to content

fix(plots): support DataArray and Dataset for y_obs in plot_lm (#454) - #543

Open
b25cs1051-KUSH wants to merge 2 commits into
arviz-devs:mainfrom
b25cs1051-KUSH:fix-plot-lm-y-obs-dataarray
Open

fix(plots): support DataArray and Dataset for y_obs in plot_lm (#454)#543
b25cs1051-KUSH wants to merge 2 commits into
arviz-devs:mainfrom
b25cs1051-KUSH:fix-plot-lm-y-obs-dataarray

Conversation

@b25cs1051-KUSH

@b25cs1051-KUSH b25cs1051-KUSH commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Why these changes were made:

  • DataArray input for y_obs was resulting in a KeyError. Updated the code to support passing DataArrays directly and bypassing extract().
  • Added a unit test to verify DataArray support.
    (Note: The custom string naming issue was already resolved in a previous commit, so no changes were made to that logic).

@codecov-commenter

codecov-commenter commented Jul 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.61%. Comparing base (9eb22b0) to head (8edf382).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/arviz_plots/plots/lm_plot.py 80.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #543      +/-   ##
==========================================
- Coverage   88.63%   88.61%   -0.02%     
==========================================
  Files          64       64              
  Lines        7266     7273       +7     
==========================================
+ Hits         6440     6445       +5     
- Misses        826      828       +2     

☔ 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.

@read-the-docs-community

read-the-docs-community Bot commented Jul 25, 2026

Copy link
Copy Markdown

@OriolAbril OriolAbril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The PR description says:

For xr.DataArray / xr.Dataset: We now bypass extract() entirely, wrap the array cleanly, and align the names.

So far so good, the code shows extract is skipped and aligned observed_y as a Dataset and y_obs as a list of variables in that dataset always exit the if.

For str / list[str]: We use extract(), but then explicitly rename the target variable to align with the x_pred coordinates so the downstream plotting functions can digest it seamlessly.

I don't see any change to how str/list of str inputs behave being done in this PR.


In the hopes of seeing you contribute more often, we don't care about the prose quality/literacy of PR descriptions and comments. In fact, PR descriptions repeating the issue and describing the changes are generally useless. We need to (and will) review the changes even if it takes us a while. Therefore, the best PR descriptions focus on why those changes were done, known tradeoffs or limitations and things that might not be straightforward to parse from the code itself.

Here for example the key information seems to be:

  • Naming issue was already fixed so no changes on that, there is also a test for that even
  • DataArray input was still not handled so updated the code to support that and added a test

Comment thread src/arviz_plots/plots/lm_plot.py Outdated
Comment on lines 325 to 330
@@ -328,16 +328,32 @@ def plot_lm(
y_obs = y
else:
y_obs = obs_vars[: len(y)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we can move this inside the else to reduce the complexity of the if clauses. In pseudocode:

if DataArray:
    ...
if Dataset:
    ...
else:
    if None:
        ...
    if str:
        ...
    extract()

@b25cs1051-KUSH

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback on PR descriptions. I will make sure that I follow the same as I continue to contribute...
Also I have refactored the if/else block to match your pseudocode and pushed the update. Let me know if it looks cleaner!

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