Skip to content
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

Merged
merged 10 commits into from
Mar 7, 2019

Conversation

Ban-zee
Copy link
Contributor

@Ban-zee Ban-zee commented Feb 26, 2019

Made the following changes:

  • Using inference data or xr.dataset with plot_kde now raises an error prompting the user to use plot_posterior instead.
  • Rug plots displayed by default for plot_posterior plots.
  • Not included the tests yet.

@Ban-zee Ban-zee changed the title Made the following additions: Addressing issue number #470 (using plot_kde with inference data object) Feb 26, 2019
@Ban-zee
Copy link
Contributor Author

Ban-zee commented Feb 28, 2019

pylint failing because of the following :
E:301,17: Instance of 'InferenceData' has no 'posterior' member (no-member)
for the following code:
with pytest.raises(ValueError, match="Xarray"): plot_kde(eight.posterior)
Any idea on how to resolve this issue?

@canyon289
Copy link
Member

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
https://docs.pytest.org/en/latest/assert.html#assertions-about-expected-exceptions

@@ -6,7 +6,7 @@
import numpy as np
import pytest
import pymc3 as pm

import arviz as az
Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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

Copy link
Contributor Author

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.

@@ -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")
Copy link
Contributor

@aloctavodia aloctavodia Mar 1, 2019

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.

@@ -358,6 +358,7 @@ def format_axes():
fill_kwargs={"alpha": kwargs.pop("fill_alpha", 0)},
plot_kwargs={"linewidth": linewidth},
ax=ax,
rug=True,
Copy link
Contributor

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

@ahartikainen
Copy link
Contributor

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 master branch

git checkout master
git remote add upstream git://github.com/arviz-devs/arviz.git
git fetch upstream
git pull upstream master

Then select your branch

git checkout i-470
git rebase master

You can check your log that everything looks good.

git log --oneline

Push with force to update repo.

git push -f

Ban-zee added 8 commits March 4, 2019 17:20
 * 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.
@Ban-zee
Copy link
Contributor Author

Ban-zee commented Mar 4, 2019

Hmm, the commits were copied, should I revert back to a previous commit and push again?

@ahartikainen
Copy link
Contributor

That looks correct? Those are commits belonging to this PR right?

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Mar 4, 2019

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 :(.

@aloctavodia
Copy link
Contributor

LGTM!

raise ValueError(
"Xarray dataset object detected.Use plot_posterior,plot_denstiy,plot_joint or plot_pair"
"instead of "
"plot_kde"
Copy link
Member

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?

Copy link
Contributor Author

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 :).

Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

@@ -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"
Copy link
Member

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

Copy link
Contributor Author

@Ban-zee Ban-zee Mar 5, 2019

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.

Copy link
Member

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

@Ban-zee
Copy link
Contributor Author

Ban-zee commented Mar 5, 2019

Made the changes.

@@ -7,7 +7,7 @@
import pytest
import pymc3 as pm


from ..data import load_arviz_data
Copy link
Member

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")
Copy link
Member

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.

@canyon289
Copy link
Member

@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!

@canyon289 canyon289 merged commit 99dd219 into arviz-devs:master Mar 7, 2019
@canyon289
Copy link
Member

Thanks for help!

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.

4 participants