Skip to content

Commit 859ad24

Browse files
sinhrksjorisvandenbossche
authored andcommitted
Move tests upder plotting and other corrections
1 parent 1fba0c6 commit 859ad24

21 files changed

+136
-41
lines changed

pandas/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@
5050
merge_ordered, merge_asof)
5151
from pandas.tools.pivot import pivot_table, crosstab
5252

53-
# deprecated
53+
# deprecate tools.plotting, and directly imported scatter_matrix
5454
import pandas.tools.plotting
55-
from pandas.plotting import scatter_matrix, plot_params
55+
from pandas.plotting import plot_params
56+
from pandas.util.decorators import deprecate
57+
scatter_matrix = deprecate('pandas.scatter_matrix', pandas.plotting.scatter_matrix,
58+
'pandas.plotting.scatter_matrix')
59+
5660
from pandas.tools.tile import cut, qcut
5761
from pandas.tools.util import to_numeric
5862
from pandas.core.reshape import melt

pandas/core/frame.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import pandas.core.ops as ops
9191
import pandas.formats.format as fmt
9292
from pandas.formats.printing import pprint_thing
93-
import pandas.plotting.plotting as gfx
93+
import pandas.plotting.core as gfx
9494

9595
from pandas._libs import lib, algos as libalgos
9696

pandas/core/groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4159,7 +4159,7 @@ def groupby_series(obj, col=None):
41594159
return results
41604160

41614161

4162-
from pandas.plotting.plotting import boxplot_frame_groupby # noqa
4162+
from pandas.plotting.core import boxplot_frame_groupby # noqa
41634163
DataFrameGroupBy.boxplot = boxplot_frame_groupby
41644164

41654165

pandas/core/series.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3001,7 +3001,7 @@ def create_from_value(value, index, dtype):
30013001
# ----------------------------------------------------------------------
30023002
# Add plotting methods to Series
30033003

3004-
import pandas.plotting.plotting as _gfx # noqa
3004+
import pandas.plotting.core as _gfx # noqa
30053005

30063006
Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods,
30073007
_gfx.SeriesPlotMethods)

pandas/plotting/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
# flake8: noqa
66

77
try: # mpl optional
8-
from pandas.plotting import converter as conv
9-
conv.register() # needs to override so set_xlim works with str/number
8+
from pandas.plotting import converter
9+
converter.register() # needs to override so set_xlim works with str/number
1010
except ImportError:
1111
pass
1212

1313
from pandas.plotting.misc import (scatter_matrix, radviz,
1414
andrews_curves, bootstrap_plot,
1515
parallel_coordinates, lag_plot,
1616
autocorrelation_plot)
17-
from pandas.plotting.plotting import (boxplot, scatter_plot, grouped_hist,
18-
hist_frame, hist_series)
17+
from pandas.plotting.core import (boxplot, scatter_plot, grouped_hist,
18+
hist_frame, hist_series)
1919
from pandas.plotting.style import plot_params
20-
from pandas.plotting.tools import table
20+
from pandas.plotting.tools import table
File renamed without changes.
File renamed without changes.

pandas/tests/plotting/common.py renamed to pandas/plotting/tests/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ def setUp(self):
7373
self.default_tick_position = 'left' if self.mpl_ge_2_0_0 else 'default'
7474
# common test data
7575
from pandas import read_csv
76-
path = os.path.join(os.path.dirname(curpath()), 'data', 'iris.csv')
76+
base = os.path.join(os.path.dirname(curpath()), os.pardir)
77+
path = os.path.join(base, 'tests', 'data', 'iris.csv')
7778
self.iris = read_csv(path)
7879

7980
n = 100

pandas/tests/plotting/test_boxplot_method.py renamed to pandas/plotting/tests/test_boxplot_method.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from numpy import random
1515
from numpy.random import randn
1616

17-
import pandas.tools.plotting as plotting
17+
import pandas.plotting as plotting
1818

19-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works)
19+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works)
2020

2121

2222
""" Test cases for .boxplot method """

pandas/tests/plotting/test_datetimelike.py renamed to pandas/plotting/tests/test_datetimelike.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pandas.util.testing import assert_series_equal, ensure_clean, slow
1818
import pandas.util.testing as tm
1919

20-
from pandas.tests.plotting.common import (TestPlotBase,
20+
from pandas.plotting.tests.common import (TestPlotBase,
2121
_skip_if_no_scipy_gaussian_kde)
2222

2323

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# coding: utf-8
2+
3+
import nose
4+
import string
5+
6+
import pandas as pd
7+
import pandas.util.testing as tm
8+
from pandas.util.testing import slow
9+
10+
import numpy as np
11+
from numpy.random import randn
12+
13+
import pandas.tools.plotting as plotting
14+
15+
from pandas.plotting.tests.common import TestPlotBase
16+
17+
18+
"""
19+
Test cases for plot functions imported from deprecated
20+
pandas.tools.plotting
21+
"""
22+
23+
24+
@tm.mplskip
25+
class TestDeprecatedNameSpace(TestPlotBase):
26+
27+
@slow
28+
def test_scatter_plot_legacy(self):
29+
tm._skip_if_no_scipy()
30+
31+
df = pd.DataFrame(randn(100, 2))
32+
33+
with tm.assert_produces_warning(FutureWarning):
34+
plotting.scatter_matrix(df)
35+
36+
with tm.assert_produces_warning(FutureWarning):
37+
pd.scatter_matrix(df)
38+
39+
@slow
40+
def test_boxplot_deprecated(self):
41+
df = pd.DataFrame(randn(6, 4),
42+
index=list(string.ascii_letters[:6]),
43+
columns=['one', 'two', 'three', 'four'])
44+
df['indic'] = ['foo', 'bar'] * 3
45+
46+
with tm.assert_produces_warning(FutureWarning):
47+
plotting.boxplot(df, column=['one', 'two'],
48+
by='indic')
49+
50+
@slow
51+
def test_grouped_hist_legacy(self):
52+
df = pd.DataFrame(randn(500, 2), columns=['A', 'B'])
53+
df['C'] = np.random.randint(0, 4, 500)
54+
df['D'] = ['X'] * 500
55+
56+
with tm.assert_produces_warning(FutureWarning):
57+
plotting.grouped_hist(df.A, by=df.C)
58+
59+
@slow
60+
def test_radviz_deprecated(self):
61+
df = self.iris
62+
with tm.assert_produces_warning(FutureWarning):
63+
plotting.radviz(frame=df, class_column='Name')
64+
65+
66+
if __name__ == '__main__':
67+
nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'],
68+
exit=False)

pandas/tests/plotting/test_frame.py renamed to pandas/plotting/tests/test_frame.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from numpy.random import rand, randn
2424

2525
import pandas.plotting as plotting
26-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
26+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works,
2727
_skip_if_no_scipy_gaussian_kde,
2828
_ok_for_gaussian_kde)
2929

@@ -1979,7 +1979,7 @@ def test_unordered_ts(self):
19791979

19801980
def test_kind_both_ways(self):
19811981
df = DataFrame({'x': [1, 2, 3]})
1982-
for kind in plotting.plotting._common_kinds:
1982+
for kind in plotting.core._common_kinds:
19831983
if not _ok_for_gaussian_kde(kind):
19841984
continue
19851985
df.plot(kind=kind)
@@ -1990,7 +1990,7 @@ def test_kind_both_ways(self):
19901990

19911991
def test_all_invalid_plot_data(self):
19921992
df = DataFrame(list('abcd'))
1993-
for kind in plotting.plotting._common_kinds:
1993+
for kind in plotting.core._common_kinds:
19941994
if not _ok_for_gaussian_kde(kind):
19951995
continue
19961996
with tm.assertRaises(TypeError):
@@ -2001,7 +2001,7 @@ def test_partially_invalid_plot_data(self):
20012001
with tm.RNGContext(42):
20022002
df = DataFrame(randn(10, 2), dtype=object)
20032003
df[np.random.rand(df.shape[0]) > 0.5] = 'a'
2004-
for kind in plotting.plotting._common_kinds:
2004+
for kind in plotting.core._common_kinds:
20052005
if not _ok_for_gaussian_kde(kind):
20062006
continue
20072007
with tm.assertRaises(TypeError):
@@ -2454,7 +2454,7 @@ def test_memory_leak(self):
24542454
import gc
24552455

24562456
results = {}
2457-
for kind in plotting.plotting._plot_klass.keys():
2457+
for kind in plotting.core._plot_klass.keys():
24582458
if not _ok_for_gaussian_kde(kind):
24592459
continue
24602460
args = {}
@@ -2653,7 +2653,7 @@ def test_df_grid_settings(self):
26532653
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
26542654
self._check_grid_settings(
26552655
DataFrame({'a': [1, 2, 3], 'b': [2, 3, 4]}),
2656-
plotting.plotting._dataframe_kinds, kws={'x': 'a', 'y': 'b'})
2656+
plotting.core._dataframe_kinds, kws={'x': 'a', 'y': 'b'})
26572657

26582658
def test_option_mpl_style(self):
26592659
with tm.assert_produces_warning(FutureWarning,

pandas/tests/plotting/test_groupby.py renamed to pandas/plotting/tests/test_groupby.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import numpy as np
1010

11-
from pandas.tests.plotting.common import TestPlotBase
11+
from pandas.plotting.tests.common import TestPlotBase
1212

1313

1414
@tm.mplskip

pandas/tests/plotting/test_hist_method.py renamed to pandas/plotting/tests/test_hist_method.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import numpy as np
1010
from numpy.random import randn
1111

12-
import pandas.tools.plotting as plotting
13-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works)
12+
import pandas.plotting as plotting
13+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works)
1414

1515

1616
@tm.mplskip

pandas/tests/plotting/test_misc.py renamed to pandas/plotting/tests/test_misc.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from numpy import random
1212
from numpy.random import randn
1313

14-
import pandas.tools.plotting as plotting
15-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
14+
import pandas.plotting as plotting
15+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works,
1616
_ok_for_gaussian_kde)
1717

1818

@@ -29,7 +29,7 @@ def setUp(self):
2929

3030
@slow
3131
def test_autocorrelation_plot(self):
32-
from pandas.tools.plotting import autocorrelation_plot
32+
from pandas.plotting import autocorrelation_plot
3333
_check_plot_works(autocorrelation_plot, series=self.ts)
3434
_check_plot_works(autocorrelation_plot, series=self.ts.values)
3535

@@ -38,13 +38,13 @@ def test_autocorrelation_plot(self):
3838

3939
@slow
4040
def test_lag_plot(self):
41-
from pandas.tools.plotting import lag_plot
41+
from pandas.plotting import lag_plot
4242
_check_plot_works(lag_plot, series=self.ts)
4343
_check_plot_works(lag_plot, series=self.ts, lag=5)
4444

4545
@slow
4646
def test_bootstrap_plot(self):
47-
from pandas.tools.plotting import bootstrap_plot
47+
from pandas.plotting import bootstrap_plot
4848
_check_plot_works(bootstrap_plot, series=self.ts, size=10)
4949

5050

@@ -130,7 +130,7 @@ def test_scatter_matrix_axis(self):
130130

131131
@slow
132132
def test_andrews_curves(self):
133-
from pandas.tools.plotting import andrews_curves
133+
from pandas.plotting import andrews_curves
134134
from matplotlib import cm
135135

136136
df = self.iris
@@ -195,7 +195,7 @@ def test_andrews_curves(self):
195195

196196
@slow
197197
def test_parallel_coordinates(self):
198-
from pandas.tools.plotting import parallel_coordinates
198+
from pandas.plotting import parallel_coordinates
199199
from matplotlib import cm
200200

201201
df = self.iris
@@ -263,7 +263,7 @@ def test_parallel_coordinates_with_sorted_labels(self):
263263

264264
@slow
265265
def test_radviz(self):
266-
from pandas.tools.plotting import radviz
266+
from pandas.plotting import radviz
267267
from matplotlib import cm
268268

269269
df = self.iris

pandas/tests/plotting/test_series.py renamed to pandas/plotting/tests/test_series.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from numpy.random import randn
1818

1919
import pandas.plotting as plotting
20-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
20+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works,
2121
_skip_if_no_scipy_gaussian_kde,
2222
_ok_for_gaussian_kde)
2323

@@ -622,8 +622,8 @@ def test_boxplot_series(self):
622622
@slow
623623
def test_kind_both_ways(self):
624624
s = Series(range(3))
625-
kinds = (plotting.plotting._common_kinds +
626-
plotting.plotting._series_kinds)
625+
kinds = (plotting.core._common_kinds +
626+
plotting.core._series_kinds)
627627
for kind in kinds:
628628
if not _ok_for_gaussian_kde(kind):
629629
continue
@@ -633,7 +633,7 @@ def test_kind_both_ways(self):
633633
@slow
634634
def test_invalid_plot_data(self):
635635
s = Series(list('abcd'))
636-
for kind in plotting.plotting._common_kinds:
636+
for kind in plotting.core._common_kinds:
637637
if not _ok_for_gaussian_kde(kind):
638638
continue
639639
with tm.assertRaises(TypeError):
@@ -642,14 +642,14 @@ def test_invalid_plot_data(self):
642642
@slow
643643
def test_valid_object_plot(self):
644644
s = Series(lrange(10), dtype=object)
645-
for kind in plotting.plotting._common_kinds:
645+
for kind in plotting.core._common_kinds:
646646
if not _ok_for_gaussian_kde(kind):
647647
continue
648648
_check_plot_works(s.plot, kind=kind)
649649

650650
def test_partially_invalid_plot_data(self):
651651
s = Series(['a', 'b', 1.0, 2])
652-
for kind in plotting.plotting._common_kinds:
652+
for kind in plotting.core._common_kinds:
653653
if not _ok_for_gaussian_kde(kind):
654654
continue
655655
with tm.assertRaises(TypeError):
@@ -720,8 +720,8 @@ def test_table(self):
720720
def test_series_grid_settings(self):
721721
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
722722
self._check_grid_settings(Series([1, 2, 3]),
723-
plotting.plotting._series_kinds +
724-
plotting.plotting._common_kinds)
723+
plotting.core._series_kinds +
724+
plotting.core._common_kinds)
725725

726726
@slow
727727
def test_standard_colors(self):

pandas/plotting/timeseries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def _replot_ax(ax, freq, kwargs):
134134

135135
# for tsplot
136136
if isinstance(plotf, compat.string_types):
137-
from pandas.tools.plotting import _plot_klass
137+
from pandas.plotting.core import _plot_klass
138138
plotf = _plot_klass[plotf]._plot
139139

140140
lines.append(plotf(ax, series.index._mpl_repr(),

pandas/tools/plotting.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
import warnings
3+
4+
import pandas.plotting.api as api
5+
6+
# back-compat of public API
7+
# deprecate these functions
8+
m = sys.modules['pandas.tools.plotting']
9+
for t in [t for t in dir(api) if not t.startswith('_')]:
10+
11+
def outer(t=t):
12+
13+
def wrapper(*args, **kwargs):
14+
warnings.warn("pandas.tools.plotting.{t} is deprecated. "
15+
"import from the "
16+
"pandas.plotting.{t} instead".format(t=t),
17+
FutureWarning, stacklevel=2)
18+
return getattr(api, t)(*args, **kwargs)
19+
return wrapper
20+
21+
setattr(m, t, outer(t))

pandas/util/doctools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _make_table(self, ax, df, title, height=None):
131131
ax.set_visible(False)
132132
return
133133

134-
import pandas.tools.plotting as plotting
134+
import pandas.plotting as plotting
135135

136136
idx_nlevels = df.index.nlevels
137137
col_nlevels = df.columns.nlevels

0 commit comments

Comments
 (0)