Skip to content

Commit

Permalink
CLN: Remove unused imports
Browse files Browse the repository at this point in the history
Remove imports of matplotlib that are no longer needed
  • Loading branch information
bashtage committed Sep 12, 2018
1 parent 492845b commit 4b30aeb
Show file tree
Hide file tree
Showing 29 changed files with 135 additions and 211 deletions.
5 changes: 3 additions & 2 deletions statsmodels/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def pytest_runtest_setup(item):
if 'example' in item.keywords and item.config.getoption("--skip-examples"):
pytest.skip("skipping due to --skip-examples")

if 'requires_matplotlib' in item.keywords and item.config.getoption("--skip-matplotlib"):
if 'matplotlib' in item.keywords and \
item.config.getoption("--skip-matplotlib"):
pytest.skip("skipping due to --skip-matplotlib")

if 'requires_matplotlib' in item.keywords and not HAVE_MATPLOTLIB:
if 'matplotlib' in item.keywords and not HAVE_MATPLOTLIB:
pytest.skip("skipping since matplotlib is not intalled")


Expand Down
9 changes: 3 additions & 6 deletions statsmodels/discrete/tests/test_diagnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import numpy as np
from numpy.testing import assert_allclose
import pytest

from statsmodels.discrete.discrete_model import Poisson
import statsmodels.discrete._diagnostics_count as dia
Expand Down Expand Up @@ -57,6 +58,7 @@ def test_count(self):
tzi3_1 = (0.79863597832443878, 0.67077736750318928, 2, 2)
assert_allclose(tzi3, tzi3_1, rtol=5e-4)

@pytest.mark.matplotlib
def test_probs(self, close_figures):
nobs = self.nobs
probs = self.res.predict_prob()
Expand All @@ -68,9 +70,4 @@ def test_probs(self, close_figures):
assert_allclose(tzi[:2], tzi1, rtol=5e-5)

# smoke test for plot

try:
import matplotlib.pyplot as plt
except ImportError:
return
fig = dia.plot_probs(freq, probs.mean(0))
dia.plot_probs(freq, probs.mean(0))
2 changes: 1 addition & 1 deletion statsmodels/duration/tests/test_survfunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def test_survdiff():
assert_allclose(stat, 13.35259, atol=1e-4, rtol=1e-4)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_km(close_figures):

if pdf_output:
Expand Down
6 changes: 3 additions & 3 deletions statsmodels/genmod/tests/test_gee.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def test_margins_multinomial(self):
assert_allclose(marg.margeff, np.r_[-0.41197961], rtol=1e-5)
assert_allclose(marg.margeff_se, np.r_[0.1379962], rtol=1e-6)

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_nominal_plot(self, close_figures):
np.random.seed(34234)
endog = np.r_[0, 0, 0, 0, 1, 1, 1, 1]
Expand Down Expand Up @@ -801,7 +801,7 @@ def test_nominal_independence(self):
model1 = NominalGEE(y, x, groups, cov_struct=nmi)
model1.fit()

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_ordinal_plot(self, close_figures):
family = Binomial()

Expand Down Expand Up @@ -1554,7 +1554,7 @@ def test_wrapper(self):
check_wrapper(rslt2)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plots(close_figures):

np.random.seed(378)
Expand Down
8 changes: 1 addition & 7 deletions statsmodels/genmod/tests/test_glm.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@
DECIMAL_1 = 1
DECIMAL_0 = 0

try:
import matplotlib.pyplot as plt
except:
pass

pdf_output = False

if pdf_output:
Expand Down Expand Up @@ -901,7 +896,7 @@ def test_formula_missing_exposure():
exposure=exposure, family=family)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plots(close_figures):

np.random.seed(378)
Expand All @@ -914,7 +909,6 @@ def test_plots(close_figures):
model = sm.GLM(endog, exog, family=sm.families.Binomial())
result = model.fit()

import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.graphics.regressionplots import add_lowess

Expand Down
2 changes: 1 addition & 1 deletion statsmodels/graphics/tests/test_agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
pass


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_mean_diff_plot(close_figures):

# Seed the random number generator.
Expand Down
2 changes: 1 addition & 1 deletion statsmodels/graphics/tests/test_boxplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
pass


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_violinplot_beanplot(close_figures):
# Test violinplot and beanplot with the same dataset.
data = anes96.load_pandas()
Expand Down
9 changes: 2 additions & 7 deletions statsmodels/graphics/tests/test_correlation.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@
from statsmodels.graphics.correlation import plot_corr, plot_corr_grid
from statsmodels.datasets import randhie

try:
import matplotlib.pyplot as plt
except ImportError:
pass


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_corr(close_figures):
hie_data = randhie.load_pandas()
corr_matrix = np.corrcoef(hie_data.data.values.T)
Expand All @@ -22,7 +17,7 @@ def test_plot_corr(close_figures):
plot_corr(corr_matrix, normcolor=True, title='', cmap='jet')


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_corr_grid(close_figures):
hie_data = randhie.load_pandas()
corr_matrix = np.corrcoef(hie_data.data.values.T)
Expand Down
3 changes: 1 addition & 2 deletions statsmodels/graphics/tests/test_dotplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

try:
import matplotlib.pyplot as plt
import matplotlib
except ImportError:
pass

Expand All @@ -19,7 +18,7 @@ def close_or_save(pdf, fig):
pdf.savefig(fig)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_all(close_figures):

if pdf_output:
Expand Down
15 changes: 7 additions & 8 deletions statsmodels/graphics/tests/test_factorplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

try:
import matplotlib.pyplot as plt
import matplotlib
except ImportError:
pass

Expand All @@ -21,17 +20,17 @@ def setup_class(cls):
cls.duration = np.random.randint(1,3,size=60)
cls.days = np.log(np.random.randint(1,30, size=60))

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_both(self, close_figures):
fig = interaction_plot(self.weight, self.duration, self.days,
colors=['red','blue'], markers=['D','^'], ms=10)

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_rainbow(self, close_figures):
fig = interaction_plot(self.weight, self.duration, self.days,
markers=['D','^'], ms=10)

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_pandas(self, close_figures):
weight = Series(self.weight, name='Weight')
duration = Series(self.duration, name='Duration')
Expand All @@ -44,7 +43,7 @@ def test_plot_pandas(self, close_figures):
assert_equal(ax.get_ylabel(), 'mean of Days')
assert_equal(ax.get_xlabel(), 'Weight')

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plot_string_data(self, close_figures):
weight = Series(self.weight, name='Weight').astype('str')
duration = Series(self.duration, name='Duration')
Expand All @@ -57,18 +56,18 @@ def test_plot_string_data(self, close_figures):
assert_equal(ax.get_ylabel(), 'mean of Days')
assert_equal(ax.get_xlabel(), 'Weight')

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_formatting(self, close_figures):
fig = interaction_plot(self.weight, self.duration, self.days, colors=['r','g'], linestyles=['--','-.'])
assert_equal(isinstance(fig, plt.Figure), True)

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_formatting_errors(self, close_figures):
assert_raises(ValueError, interaction_plot, self.weight, self.duration, self.days, markers=['D'])
assert_raises(ValueError, interaction_plot, self.weight, self.duration, self.days, colors=['b','r','g'])
assert_raises(ValueError, interaction_plot, self.weight, self.duration, self.days, linestyles=['--','-.',':'])

@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_plottype(self, close_figures):
fig = interaction_plot(self.weight, self.duration, self.days, plottype='line')
assert_equal(isinstance(fig, plt.Figure), True)
Expand Down
18 changes: 9 additions & 9 deletions statsmodels/graphics/tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
data = data.raw_data[:, 1:]


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_basic(close_figures):
_, hdr = hdrboxplot(data, labels=labels, seed=12345)

Expand Down Expand Up @@ -57,7 +57,7 @@ def test_hdr_basic(close_figures):
assert_equal(labels[hdr.outliers_idx], outliers)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_basic_brute(close_figures):
_, hdr = hdrboxplot(data, labels=labels, use_brute=True)

Expand All @@ -69,7 +69,7 @@ def test_hdr_basic_brute(close_figures):
assert_almost_equal(hdr.median, median_t, decimal=2)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_plot(close_figures):
fig = plt.figure()
ax = fig.add_subplot(111)
Expand All @@ -83,7 +83,7 @@ def test_hdr_plot(close_figures):
ax.set_xlim([-0.2, 11.2])


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_alpha(close_figures):
_, hdr = hdrboxplot(data, alpha=[0.7], seed=12345)
extra_quant_t = np.vstack([[25.1, 26.5, 27.0, 26.4, 25.4, 24.1,
Expand All @@ -93,7 +93,7 @@ def test_hdr_alpha(close_figures):
assert_almost_equal(hdr.extra_quantiles, extra_quant_t, decimal=0)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_multiple_alpha(close_figures):
_, hdr = hdrboxplot(data, alpha=[0.4, 0.92], seed=12345)
extra_quant_t = [[25.712, 27.052, 27.711, 27.200,
Expand All @@ -112,7 +112,7 @@ def test_hdr_multiple_alpha(close_figures):
decimal=0)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_threshold(close_figures):
_, hdr = hdrboxplot(data, alpha=[0.8], threshold=0.93, seed=12345)
labels_pos = np.all(np.in1d(data, hdr.outliers).reshape(data.shape),
Expand All @@ -121,15 +121,15 @@ def test_hdr_threshold(close_figures):
assert_equal([1968, 1982, 1983, 1997, 1998], outliers)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_bw(close_figures):
_, hdr = hdrboxplot(data, bw='cv_ml', seed=12345)
median_t = [24.25, 25.64, 25.99, 25.04, 23.71, 22.38,
21.31, 20.44, 20.24, 20.51, 21.19, 22.38]
assert_almost_equal(hdr.median, median_t, decimal=2)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_hdr_ncomp(close_figures):
_, hdr = hdrboxplot(data, ncomp=3, seed=12345)
median_t = [24.33, 25.71, 26.04, 25.08, 23.74, 22.40,
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_banddepth_MBD():
assert_almost_equal(depth, expected_depth, decimal=4)


@pytest.mark.requires_matplotlib
@pytest.mark.matplotlib
def test_fboxplot_rainbowplot(close_figures):
# Test fboxplot and rainbowplot together, is much faster.
def harmfunc(t):
Expand Down
Loading

0 comments on commit 4b30aeb

Please sign in to comment.