REF/TST: `ProbPlot` now uses `resettable_cache` and added some kwargs to plotting fxns #1179

Merged
merged 5 commits into from Dec 24, 2013

Projects

None yet

3 participants

@phobson
Contributor
phobson commented Nov 10, 2013

Also reworked the tests.

@coveralls

Coverage Status

Coverage remained the same when pulling a679b71 on phobson:ProbPlot-enhancements-and-tests into 9d4b1f8 on statsmodels:master.

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/gofplots.py
except TypeError:
- print('%s requires more parameters to compute ppf' % \
- (self.dist.name,))
+ msg = '%s requires more parameters to ' \
+ 'compute ppf'.format(self.dist.name,)
+ print(msg)
@josef-pkt
josef-pkt Dec 1, 2013 Member

we should use warnings.warn instead of print statements

should this raise an exception?

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/gofplots.py
return self.dist.cdf(qntls)
- def ppplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
+ def ppplot(self, ax=None, xlabel=None, ylabel=None, line=None, other=None,
+ **plotkwargs):
@josef-pkt
josef-pkt Dec 1, 2013 Member

I'm not sure about moving the position of ax.
I don't worry too much about backwards compatibility in this case but we should have a consistent pattern across plots.

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/gofplots.py
If provided, the sample quantiles of this `ProbPlot` instance are
plotted against the sample quantiles of the `other` `ProbPlot`
instance. If an array-like object is provided, it will be turned
into a `ProbPlot` instance using default parameters. If not provided
(default), the theoretical quantiles are used.
- ax : Matplotlib AxesSubplot instance, optional
- If given, this subplot is used to plot in instead of a new figure
- being created.
+
+ **plotkwargs : additional matplotlib arguments to be passed to the
@josef-pkt
josef-pkt Dec 1, 2013 Member

I don't think there should be a blank line before **plotkwargs

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/gofplots.py
@@ -249,19 +268,24 @@ def ppplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
return fig
- def qqplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
+ def qqplot(self, ax=None, xlabel=None, ylabel=None, line=None, other=None,
+ **plotkwargs):
@josef-pkt
josef-pkt Dec 1, 2013 Member

same here about moving ax

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/gofplots.py
- Returns
@josef-pkt
josef-pkt Dec 1, 2013 Member

accidental delete of Returns ?

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/tests/test_gofplots.py
-@dec.skipif(not have_matplotlib)
-def test_qqplot_2samples_arrays():
- #just test that it runs
- x = np.random.normal(loc=8.25, scale=3.25, size=37)
- y = np.random.normal(loc=8.25, scale=3.25, size=37)
-
- pp_x = sm.ProbPlot(x)
- pp_y = sm.ProbPlot(y)
-
- # also tests all values for line
- for line in ['r', 'q', '45', 's']:
- # test with arrays
- fig1 = sm.qqplot_2samples(x, y, line=line)
-
- plt.close('all')
+class _base_probplot:
@josef-pkt
josef-pkt Dec 1, 2013 Member

pep-8 naming Capitalization in class names
subclass object

add Mixin to end of class name to make pylint a bit happier

@josef-pkt josef-pkt commented on an outdated diff Dec 1, 2013
statsmodels/graphics/tests/test_gofplots.py
+ def setup(self):
+ self.data = np.random.normal(loc=8.25, scale=3.25, size=37)
+ self.prbplt = sm.ProbPlot(self.data, fit=True)
+ self.line = 'q'
+ self.base_setup()
+
+
+class test_ProbPlot_RandomNormal_LocScale(_base_probplot):
+ def setup(self):
+ self.data = np.random.normal(loc=8.25, scale=3.25, size=37)
+ self.prbplt = sm.ProbPlot(self.data, loc=8.25, scale=3.25)
+ self.line = '45'
+ self.base_setup()
+
+
+class test_top_level:
@josef-pkt
josef-pkt Dec 1, 2013 Member

class name should be capitalized and now undelines

@phobson
Contributor
phobson commented Dec 1, 2013

@josef-pkt I addressed all of the comments. Decided to raise errors instead of vanilla print statements

@coveralls

Coverage Status

Coverage remained the same when pulling e2694aa on phobson:ProbPlot-enhancements-and-tests into 9d4b1f8 on statsmodels:master.

@coveralls

Coverage Status

Coverage remained the same when pulling e2694aa on phobson:ProbPlot-enhancements-and-tests into 9d4b1f8 on statsmodels:master.

@josef-pkt josef-pkt commented on the diff Dec 18, 2013
statsmodels/graphics/gofplots.py
Options for the reference line to which the data is compared:
-
@josef-pkt
josef-pkt Dec 18, 2013 Member

removing this line will break sphinx/rst rendering, an item list needs to be preceded by a blank line (even if it doesn't always look nice in source)

@josef-pkt
josef-pkt Dec 24, 2013 Member

blank line missing, needs doc build to check

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/gofplots.py
"""
P-P plot of the percentiles (probabilities) of x versus the
probabilities (percetiles) of a distribution.
Parameters
----------
- xlabel, ylabel : str or None
+ ax : Matplotlib AxesSubplot instance, optional
@josef-pkt
josef-pkt Dec 18, 2013 Member

ax is now in the wrong position in docstring, given that it's again the last explicit keyword

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/gofplots.py
@@ -247,21 +262,22 @@ def ppplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
return fig
- return fig
-
- def qqplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
+ def qqplot(self, xlabel=None, ylabel=None, line=None, other=None,
+ ax=None, **plotkwargs):
@josef-pkt
josef-pkt Dec 18, 2013 Member

STY (minor) one space too many in intend

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/gofplots.py
"""
Q-Q plot of the quantiles of x versus the quantiles/ppf of a
distribution or the quantiles of another `ProbPlot` instance.
Parameters
----------
- xlabel, ylabel : str or None
+ ax : Matplotlib AxesSubplot instance, optional
@josef-pkt
josef-pkt Dec 18, 2013 Member

also ax is now in wrong position in Parameters list

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/gofplots.py
@@ -316,7 +332,8 @@ def qqplot(self, xlabel=None, ylabel=None, line=None, other=None, ax=None):
return fig
- def probplot(self, line=None, ax=None, exceed=False):
+ def probplot(self, ax=None, xlabel=None, ylabel=None, line=None,
@josef-pkt
josef-pkt Dec 18, 2013 Member

ax in second position,
we should have consistent sequencing of arguments

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/gofplots.py
@@ -339,10 +363,7 @@ def probplot(self, line=None, ax=None, exceed=False):
- If True a reference line is drawn on the graph. The default is to
fit a line via OLS regression.
- ax : Matplotlib AxesSubplot instance, optional
- If given, this subplot is used to plot in instead of a new figure
- being created.
- excced : boolean
+ excced : boolean, optional
@josef-pkt
josef-pkt Dec 18, 2013 Member

typo exceed

@josef-pkt josef-pkt commented on the diff Dec 18, 2013
statsmodels/graphics/tests/test_gofplots.py
+ markeredgecolor='white',
+ alpha=0.5)
+
+
+class TestProbPlotLongely(BaseProbplotMixin):
+ def setup(self):
+ self.data = sm.datasets.longley.load()
+ self.data.exog = sm.add_constant(self.data.exog, prepend=False)
+ self.mod_fit = sm.OLS(self.data.endog, self.data.exog).fit()
+ self.prbplt = sm.ProbPlot(self.mod_fit.resid, stats.t, distargs=(4,))
+ self.line = 'r'
+ self.base_setup()
+
+
+class TestProbPlotRandomNormalMinimal(BaseProbplotMixin):
+ def setup(self):
@josef-pkt
josef-pkt Dec 18, 2013 Member

add random.seed here and at all the similar classes below

@josef-pkt josef-pkt commented on an outdated diff Dec 18, 2013
statsmodels/graphics/tests/test_gofplots.py
@@ -1,4 +1,5 @@
import numpy as np
+np.random.seed(5)
@josef-pkt
josef-pkt Dec 18, 2013 Member

random seed should not be on top of a module
should be in front of the random number generation to make it replicable. Rearranging tests will change random seeds used in the different tests, also nosetests runs tests in a sequence that will change if a new test is added.

@josef-pkt
Member

I'm going to try out some examples, and would like to merge this today or this week.

Can you rebase on current master and force push? Otherwise, I will rebase before merging.

@phobson
Contributor
phobson commented Dec 18, 2013

@josef-pkt I'll try to get to this later tonight (west coast time). I appreciate all of your comments and rebasing won't be a problem for me.

@josef-pkt
Member

Thanks, I'd like to merge this by Friday (before kids go on vacation and my attention span will become very short)

phobson added some commits Nov 10, 2013
@phobson phobson ENH: moved probplot over to properties and added some kwargs to plott…
…ing fxns

Also reworked the tests.

BUG: fixed a 'call' to a property

BUG: fixed missing paren in sample_percentile equation

WIP: trying out this cache_readonly decorator

TST: beefier, class-based tests

TST: decorating methods, not test classes + fixed a function call

TST/BUG: fixed references to class attributes

TST/BUG: fixed references to class attributes (part2)

TST/BUG: using the right type of cache

TST/BUG: fixed references to class attributes (part3)
c59529c
@phobson phobson MNT: doc string formats, error raising, and kwarg order per comments …
…in PR
669bc27
@phobson phobson MNT: test class names (capitalized) and trailing spaces 69cf659
@phobson phobson MNT: more trailing space 853d345
@phobson phobson DOC/TST: fixed from docstring styles/typos and moved therandom seed t…
…o the setup methods of the tests
f047d54
@coveralls

Coverage Status

Changes Unknown when pulling f047d54 on phobson:ProbPlot-enhancements-and-tests into * on statsmodels:master*.

@phobson
Contributor
phobson commented Dec 22, 2013

@josef-pkt sorry that took so long.

@josef-pkt
Member

Thanks, I try to merge it soon.

One git tip: you can set global config options to warn or remove trailing whitespace (in case they were yours)
One Windows automatic removing trailing whitespace on commit doesn't work. But it works during rebase, and when I rebase a branch then trailing whitespaces are corrected and removed from the commits.

@phobson
Contributor
phobson commented Dec 22, 2013

Are they there now? I've got sublime text configured to hightlingand trim
trailing white space

On Sun, Dec 22, 2013 at 5:45 AM, Josef Perktold notifications@github.comwrote:

Thanks, I try to merge it soon.

One git tip: you can set global config options to warn or remove trailing
whitespace (in case they were yours)
One Windows automatic removing trailing whitespace on commit doesn't work.
But it works during rebase, and when I rebase a branch then trailing
whitespaces are corrected and removed from the commits.


Reply to this email directly or view it on GitHubhttps://github.com/statsmodels/statsmodels/pull/1179#issuecomment-31087679
.

@josef-pkt
Member

Are they there now?

I haven't checked and assume not. This was based on the commit messages about trailing whitespace.

@phobson
Contributor
phobson commented Dec 22, 2013

Ok. Gotcha. Thanks. That commit was when I was ironing on the configuration on a new virtual machine. --
Paul Hobson
Sorry if this is unintelligible. I'm on my phone.

On Sun, Dec 22, 2013 at 8:59 AM, Josef Perktold notifications@github.com
wrote:

Are they there now?

I haven't checked and assume not. This was based on the commit messages about trailing whitespace.

Reply to this email directly or view it on GitHub:
#1179 (comment)

@josef-pkt
Member

Quickly reading through this, I don't see any problems anymore.

doc build will show if current plots in the documentation change, since the unit tests are only smoketests.
I don't see any changes that would be backwards compatible for using plots (cached attribute access is mostly internal)

@josef-pkt josef-pkt merged commit be7d4e9 into statsmodels:master Dec 24, 2013

1 check passed

default The Travis CI build passed
Details
@josef-pkt
Member

merged

Thank you @phobson

@phobson phobson deleted the phobson:ProbPlot-enhancements-and-tests branch Dec 24, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment