-
-
Notifications
You must be signed in to change notification settings - Fork 421
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
Addressing issue number #470 (using plot_kde with inference data object) #600
Conversation
pylint failing because of the following : |
The first one you likely need to disable The second one might be a real error. I would check the exception to ensure its the correct one thats being raised. The pytest documentation can help you understand how the exception is being handled |
arviz/tests/test_plots.py
Outdated
@@ -6,7 +6,7 @@ | |||
import numpy as np | |||
import pytest | |||
import pymc3 as pm | |||
|
|||
import arviz as az |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a relative import from arviz, not an absolute import
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pylint keeps throwing the following exception: Inference Data has no 'posterior' member. Any explanation as to why this happens?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Its because az.InferenceData
has no posterior member :) at least during static code introspection.
If you look at the code for InferenceData posterior isn't explicitly called out, it's generated during initialization of the class. But pylint only statically analyzes code so when it "looks" it can't find anything and throws the exception.
In our case that error should be surpressed. The reason you in particular are getting so many issues is because pylint released a new version in the last couple of days, and now this PR is getting hit with all the linting errors.
My suggestion to you is to ignore the linting errors in CI for now. Just make sure it passes in your local environment. Someone will likely make a PR in the next couple of days that handles all the new linting rules, at which point it'll get merged, and this PR can merge or rebase in the new changes. Hope that helps
https://github.com/arviz-devs/arviz/blob/master/arviz/data/inference_data.py#L24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests do pass on my local environment. Thank you for the explanation. In the meantime, I'll start working on a different issue.
arviz/plots/kdeplot.py
Outdated
@@ -146,6 +147,10 @@ def plot_kde( | |||
|
|||
figsize, *_, xt_labelsize, linewidth, markersize = _scale_fig_size(figsize, textsize, 1, 1) | |||
|
|||
if isinstance(values, xr.Dataset): | |||
raise ValueError("Xarray dataset object detected. Use plot_posterior instead of plot_kde") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest the user to use plot_posterior, plot_density, plot_joint or plot_pair.
arviz/plots/posteriorplot.py
Outdated
@@ -358,6 +358,7 @@ def format_axes(): | |||
fill_kwargs={"alpha": kwargs.pop("fill_alpha", 0)}, | |||
plot_kwargs={"linewidth": linewidth}, | |||
ax=ax, | |||
rug=True, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default value should be False
, just to keep this plot close to the originals by Kruschke
This PR needs to be rebased against the current Master. It contains now many commits from previous PRs. This probably should work with forks: So in your ArviZ folder (forked repo) typed to terminal First select
Then select your branch
You can check your log that everything looks good.
Push with force to update repo.
|
* Using inference data or xr.dataset with plot_kde now raises an error prompting user to use plot_posterior instead. * Rug plots displayed by default for plot_posterior plots. * Not included the tests yet.
* Using inference data or xr.dataset with plot_kde now raises an error prompting user to use plot_posterior instead. * Rug plots displayed by default for plot_posterior plots. * Not included the tests yet.
Hmm, the commits were copied, should I revert back to a previous commit and push again? |
That looks correct? Those are commits belonging to this PR right? |
Yes, these commits belong to the same PR. It was an error on my part as I just read the commit messages and assumed that the commits were somehow copied :(. |
LGTM! |
arviz/plots/kdeplot.py
Outdated
raise ValueError( | ||
"Xarray dataset object detected.Use plot_posterior,plot_denstiy,plot_joint or plot_pair" | ||
"instead of " | ||
"plot_kde" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems weird there's an extra line break here. Doesn't hurt anything but just curious why its there?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial line was too long and pylint was failing. Added an extra line for the aesthetics :).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to make sure I understand "instead of plot_kde" was added for aesthetics?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.
arviz/plots/kdeplot.py
Outdated
@@ -146,6 +147,14 @@ def plot_kde( | |||
|
|||
figsize, *_, xt_labelsize, linewidth, markersize = _scale_fig_size(figsize, textsize, 1, 1) | |||
|
|||
if isinstance(values, xr.Dataset): | |||
raise ValueError( | |||
"Xarray dataset object detected.Use plot_posterior,plot_denstiy,plot_joint or plot_pair" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Density is spelled incorrectly, spaces between the different plots would be helpful when reading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make the changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, this PR is basically at the finish line. Very minor things.
Thanks so much for the contribution
Made the changes. |
arviz/tests/test_plots.py
Outdated
@@ -7,7 +7,7 @@ | |||
import pytest | |||
import pymc3 as pm | |||
|
|||
|
|||
from ..data import load_arviz_data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Being nitpicky here, can this import be combined with the import from ..data
below?
@@ -313,6 +313,14 @@ def test_plot_kde_quantiles(continuous_model, kwargs): | |||
assert axes | |||
|
|||
|
|||
def test_plot_kde_inference_data(): | |||
eight = load_arviz_data("centered_eight") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Docstring for this test would be great even if its oneline. I know we don't have docstrings for all tests but I'm trying to reverse that trend.
@Ban-zee Apologies for not getting all the comments in on the last round of review. I think you're just about there after these last changes! |
Thanks for help! |
Made the following changes: