Skip to content

Commit 2c4bbb6

Browse files
committed
Move tests upder plotting and other corrections
1 parent c545273 commit 2c4bbb6

21 files changed

+137
-43
lines changed

pandas/__init__.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,13 @@
4747
merge_ordered, merge_asof)
4848
from pandas.tools.pivot import pivot_table, crosstab
4949

50-
# deprecated
50+
# deprecate tools.plotting, and directly imported scatter_matrix
5151
import pandas.tools.plotting
52-
from pandas.plotting import scatter_matrix, plot_params
52+
from pandas.plotting import plot_params
53+
from pandas.util.decorators import deprecate
54+
scatter_matrix = deprecate('pandas.scatter_matrix', pandas.plotting.scatter_matrix,
55+
'pandas.plotting.scatter_matrix')
56+
5357
from pandas.tools.tile import cut, qcut
5458
from pandas.tools.util import to_numeric
5559
from pandas.core.reshape import melt

pandas/core/frame.py

+1-1
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
import pandas.lib as lib
9696
import pandas.algos as _algos

pandas/core/groupby.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3997,7 +3997,7 @@ def count(self):
39973997
return self._wrap_agged_blocks(data.items, list(blk))
39983998

39993999

4000-
from pandas.plotting.plotting import boxplot_frame_groupby # noqa
4000+
from pandas.plotting.core import boxplot_frame_groupby # noqa
40014001
DataFrameGroupBy.boxplot = boxplot_frame_groupby
40024002

40034003

pandas/core/series.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2997,7 +2997,7 @@ def __init__(self, *args, **kwargs):
29972997
# ----------------------------------------------------------------------
29982998
# Add plotting methods to Series
29992999

3000-
import pandas.plotting.plotting as _gfx # noqa
3000+
import pandas.plotting.core as _gfx # noqa
30013001

30023002
Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods,
30033003
_gfx.SeriesPlotMethods)

pandas/plotting/api.py

+5-5
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

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ def setUp(self):
7272
self.default_tick_position = 'left' if self.mpl_ge_2_0_0 else 'default'
7373
# common test data
7474
from pandas import read_csv
75-
path = os.path.join(os.path.dirname(curpath()), 'data', 'iris.csv')
75+
base = os.path.join(os.path.dirname(curpath()), os.pardir)
76+
path = os.path.join(base, 'tests', 'data', 'iris.csv')
7677
self.iris = read_csv(path)
7778

7879
n = 100

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

+2-2
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from pandas.util.testing import assert_series_equal, ensure_clean, slow
1515
import pandas.util.testing as tm
1616

17-
from pandas.tests.plotting.common import (TestPlotBase,
17+
from pandas.plotting.tests.common import (TestPlotBase,
1818
_skip_if_no_scipy_gaussian_kde)
1919

2020

+68
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from numpy.random import rand, randn
2222

2323
import pandas.plotting as plotting
24-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
24+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works,
2525
_skip_if_no_scipy_gaussian_kde,
2626
_ok_for_gaussian_kde)
2727

@@ -1967,7 +1967,7 @@ def test_unordered_ts(self):
19671967

19681968
def test_kind_both_ways(self):
19691969
df = DataFrame({'x': [1, 2, 3]})
1970-
for kind in plotting.plotting._common_kinds:
1970+
for kind in plotting.core._common_kinds:
19711971
if not _ok_for_gaussian_kde(kind):
19721972
continue
19731973
df.plot(kind=kind)
@@ -1978,7 +1978,7 @@ def test_kind_both_ways(self):
19781978

19791979
def test_all_invalid_plot_data(self):
19801980
df = DataFrame(list('abcd'))
1981-
for kind in plotting.plotting._common_kinds:
1981+
for kind in plotting.core._common_kinds:
19821982
if not _ok_for_gaussian_kde(kind):
19831983
continue
19841984
with tm.assertRaises(TypeError):
@@ -1989,7 +1989,7 @@ def test_partially_invalid_plot_data(self):
19891989
with tm.RNGContext(42):
19901990
df = DataFrame(randn(10, 2), dtype=object)
19911991
df[np.random.rand(df.shape[0]) > 0.5] = 'a'
1992-
for kind in plotting.plotting._common_kinds:
1992+
for kind in plotting.core._common_kinds:
19931993
if not _ok_for_gaussian_kde(kind):
19941994
continue
19951995
with tm.assertRaises(TypeError):
@@ -2442,7 +2442,7 @@ def test_memory_leak(self):
24422442
import gc
24432443

24442444
results = {}
2445-
for kind in plotting.plotting._plot_klass.keys():
2445+
for kind in plotting.core._plot_klass.keys():
24462446
if not _ok_for_gaussian_kde(kind):
24472447
continue
24482448
args = {}
@@ -2641,7 +2641,7 @@ def test_df_grid_settings(self):
26412641
# Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792
26422642
self._check_grid_settings(
26432643
DataFrame({'a': [1, 2, 3], 'b': [2, 3, 4]}),
2644-
plotting.plotting._dataframe_kinds, kws={'x': 'a', 'y': 'b'})
2644+
plotting.core._dataframe_kinds, kws={'x': 'a', 'y': 'b'})
26452645

26462646
def test_option_mpl_style(self):
26472647
with tm.assert_produces_warning(FutureWarning,

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import numpy as np
99

10-
from pandas.tests.plotting.common import TestPlotBase
10+
from pandas.plotting.tests.common import TestPlotBase
1111

1212

1313
""" Test cases for GroupBy.plot """

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

+2-2
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
""" Test cases for .hist method """

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

+8-8
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
""" Test cases for misc plot functions """
@@ -30,7 +30,7 @@ def setUp(self):
3030

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

@@ -39,13 +39,13 @@ def test_autocorrelation_plot(self):
3939

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

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

5151

@@ -124,7 +124,7 @@ def test_scatter_matrix_axis(self):
124124

125125
@slow
126126
def test_andrews_curves(self):
127-
from pandas.tools.plotting import andrews_curves
127+
from pandas.plotting import andrews_curves
128128
from matplotlib import cm
129129

130130
df = self.iris
@@ -189,7 +189,7 @@ def test_andrews_curves(self):
189189

190190
@slow
191191
def test_parallel_coordinates(self):
192-
from pandas.tools.plotting import parallel_coordinates
192+
from pandas.plotting import parallel_coordinates
193193
from matplotlib import cm
194194

195195
df = self.iris
@@ -237,7 +237,7 @@ def test_parallel_coordinates(self):
237237

238238
@slow
239239
def test_radviz(self):
240-
from pandas.tools.plotting import radviz
240+
from pandas.plotting import radviz
241241
from matplotlib import cm
242242

243243
df = self.iris

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from numpy.random import randn
1616

1717
import pandas.plotting as plotting
18-
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works,
18+
from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works,
1919
_skip_if_no_scipy_gaussian_kde,
2020
_ok_for_gaussian_kde)
2121

@@ -623,8 +623,8 @@ def test_boxplot_series(self):
623623
@slow
624624
def test_kind_both_ways(self):
625625
s = Series(range(3))
626-
kinds = (plotting.plotting._common_kinds +
627-
plotting.plotting._series_kinds)
626+
kinds = (plotting.core._common_kinds +
627+
plotting.core._series_kinds)
628628
for kind in kinds:
629629
if not _ok_for_gaussian_kde(kind):
630630
continue
@@ -634,7 +634,7 @@ def test_kind_both_ways(self):
634634
@slow
635635
def test_invalid_plot_data(self):
636636
s = Series(list('abcd'))
637-
for kind in plotting.plotting._common_kinds:
637+
for kind in plotting.core._common_kinds:
638638
if not _ok_for_gaussian_kde(kind):
639639
continue
640640
with tm.assertRaises(TypeError):
@@ -643,14 +643,14 @@ def test_invalid_plot_data(self):
643643
@slow
644644
def test_valid_object_plot(self):
645645
s = Series(lrange(10), dtype=object)
646-
for kind in plotting.plotting._common_kinds:
646+
for kind in plotting.core._common_kinds:
647647
if not _ok_for_gaussian_kde(kind):
648648
continue
649649
_check_plot_works(s.plot, kind=kind)
650650

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

727727
@slow
728728
def test_standard_colors(self):

pandas/plotting/timeseries.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _replot_ax(ax, freq, kwargs):
131131

132132
# for tsplot
133133
if isinstance(plotf, compat.string_types):
134-
from pandas.plotting.plotting import _plot_klass
134+
from pandas.plotting.core import _plot_klass
135135
plotf = _plot_klass[plotf]._plot
136136

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

pandas/tools/plotting.py

+21
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

+1-1
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)