Skip to content

Commit d4bdb0a

Browse files
remaining feedback + reorg
1 parent c6452b3 commit d4bdb0a

25 files changed

+95
-106
lines changed

pandas/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252

5353
# deprecate tools.plotting, plot_params and scatter_matrix on the top namespace
5454
import pandas.tools.plotting
55-
plot_params = pandas.plotting.style._Options(deprecated=True)
55+
plot_params = pandas.plotting._style._Options(deprecated=True)
5656
# do not import deprecate to top namespace
5757
scatter_matrix = pandas.util.decorators.deprecate(
5858
'pandas.scatter_matrix', pandas.plotting.scatter_matrix,

pandas/core/config_init.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def mpl_style_cb(key):
285285
stacklevel=5)
286286

287287
import sys
288-
from pandas.plotting.style import mpl_stylesheet
288+
from pandas.plotting._style import mpl_stylesheet
289289
global style_backup
290290

291291
val = cf.get_option(key)

pandas/core/frame.py

+5-5
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.core as gfx
93+
import pandas.plotting._core as gfx
9494

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

@@ -5909,11 +5909,11 @@ def _put_str(s, space):
59095909
@Appender(_shared_docs['boxplot'] % _shared_doc_kwargs)
59105910
def boxplot(self, column=None, by=None, ax=None, fontsize=None, rot=0,
59115911
grid=True, figsize=None, layout=None, return_type=None, **kwds):
5912-
import pandas.plotting as plots
5912+
from pandas.plotting._core import boxplot
59135913
import matplotlib.pyplot as plt
5914-
ax = plots.boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
5915-
grid=grid, rot=rot, figsize=figsize, layout=layout,
5916-
return_type=return_type, **kwds)
5914+
ax = boxplot(self, column=column, by=by, ax=ax, fontsize=fontsize,
5915+
grid=grid, rot=rot, figsize=figsize, layout=layout,
5916+
return_type=return_type, **kwds)
59175917
plt.draw_if_interactive()
59185918
return ax
59195919

pandas/core/groupby.py

+1-1
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.core 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

+1-1
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.core as _gfx # noqa
3004+
import pandas.plotting._core as _gfx # noqa
30053005

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

pandas/plotting/__init__.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,19 @@
1-
from pandas.plotting.api import * # noqa
1+
"""
2+
Plotting api
3+
"""
4+
5+
# flake8: noqa
6+
7+
try: # mpl optional
8+
from pandas.plotting import _converter
9+
_converter.register() # needs to override so set_xlim works with str/number
10+
except ImportError:
11+
pass
12+
13+
from pandas.plotting._misc import (scatter_matrix, radviz,
14+
andrews_curves, bootstrap_plot,
15+
parallel_coordinates, lag_plot,
16+
autocorrelation_plot)
17+
from pandas.plotting._core import boxplot
18+
from pandas.plotting._style import plot_params
19+
from pandas.plotting._tools import table
File renamed without changes.
File renamed without changes.

pandas/plotting/core.py renamed to pandas/plotting/_core.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@
2626
from pandas.formats.printing import pprint_thing
2727
from pandas.util.decorators import Appender
2828

29-
from pandas.plotting.compat import (_mpl_ge_1_3_1,
30-
_mpl_ge_1_5_0)
31-
from pandas.plotting.style import (mpl_stylesheet, plot_params,
32-
_get_standard_colors)
33-
from pandas.plotting.tools import (_subplots, _flatten, table,
34-
_handle_shared_axes, _get_all_lines,
35-
_get_xlim, _set_ticks_props,
36-
format_date_labels)
29+
from pandas.plotting._compat import (_mpl_ge_1_3_1,
30+
_mpl_ge_1_5_0)
31+
from pandas.plotting._style import (mpl_stylesheet, plot_params,
32+
_get_standard_colors)
33+
from pandas.plotting._tools import (_subplots, _flatten, table,
34+
_handle_shared_axes, _get_all_lines,
35+
_get_xlim, _set_ticks_props,
36+
format_date_labels)
3737

3838

3939
if _mpl_ge_1_5_0():
@@ -900,12 +900,12 @@ def _is_ts_plot(self):
900900
return not self.x_compat and self.use_index and self._use_dynamic_x()
901901

902902
def _use_dynamic_x(self):
903-
from pandas.plotting.timeseries import _use_dynamic_x
903+
from pandas.plotting._timeseries import _use_dynamic_x
904904
return _use_dynamic_x(self._get_ax(0), self.data)
905905

906906
def _make_plot(self):
907907
if self._is_ts_plot():
908-
from pandas.plotting.timeseries import _maybe_convert_index
908+
from pandas.plotting._timeseries import _maybe_convert_index
909909
data = _maybe_convert_index(self._get_ax(0), self.data)
910910

911911
x = data.index # dummy, not used
@@ -955,9 +955,9 @@ def _plot(cls, ax, x, y, style=None, column_num=None,
955955

956956
@classmethod
957957
def _ts_plot(cls, ax, x, data, style=None, **kwds):
958-
from pandas.plotting.timeseries import (_maybe_resample,
959-
_decorate_axes,
960-
format_dateaxis)
958+
from pandas.plotting._timeseries import (_maybe_resample,
959+
_decorate_axes,
960+
format_dateaxis)
961961
# accept x to be consistent with normal plot func,
962962
# x is not passed to tsplot as it uses data.index as x coordinate
963963
# column_num must be in kwds for stacking purpose

pandas/plotting/misc.py renamed to pandas/plotting/_misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from pandas.formats.printing import pprint_thing
1111

1212

13-
from pandas.plotting.style import _get_standard_colors
14-
from pandas.plotting.tools import _subplots, _set_ticks_props
13+
from pandas.plotting._style import _get_standard_colors
14+
from pandas.plotting._tools import _subplots, _set_ticks_props
1515

1616

1717
def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
File renamed without changes.

pandas/plotting/timeseries.py renamed to pandas/plotting/_timeseries.py

+1-1
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.plotting.core 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(),
File renamed without changes.

pandas/plotting/api.py

-20
This file was deleted.

pandas/tests/plotting/common.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from numpy import random
1818

1919
import pandas.plotting as plotting
20+
from pandas.plotting._tools import _flatten
2021

2122

2223
"""
@@ -48,12 +49,12 @@ def setUp(self):
4849
import matplotlib as mpl
4950
mpl.rcdefaults()
5051

51-
self.mpl_le_1_2_1 = plotting.compat._mpl_le_1_2_1()
52-
self.mpl_ge_1_3_1 = plotting.compat._mpl_ge_1_3_1()
53-
self.mpl_ge_1_4_0 = plotting.compat._mpl_ge_1_4_0()
54-
self.mpl_ge_1_5_0 = plotting.compat._mpl_ge_1_5_0()
55-
self.mpl_ge_2_0_0 = plotting.compat._mpl_ge_2_0_0()
56-
self.mpl_ge_2_0_1 = plotting.compat._mpl_ge_2_0_1()
52+
self.mpl_le_1_2_1 = plotting._compat._mpl_le_1_2_1()
53+
self.mpl_ge_1_3_1 = plotting._compat._mpl_ge_1_3_1()
54+
self.mpl_ge_1_4_0 = plotting._compat._mpl_ge_1_4_0()
55+
self.mpl_ge_1_5_0 = plotting._compat._mpl_ge_1_5_0()
56+
self.mpl_ge_2_0_0 = plotting._compat._mpl_ge_2_0_0()
57+
self.mpl_ge_2_0_1 = plotting._compat._mpl_ge_2_0_1()
5758

5859
if self.mpl_ge_1_4_0:
5960
self.bp_n_objects = 7
@@ -354,7 +355,7 @@ def _check_axes_shape(self, axes, axes_num=None, layout=None,
354355
self.assertTrue(len(ax.get_children()) > 0)
355356

356357
if layout is not None:
357-
result = self._get_axes_layout(plotting.tools._flatten(axes))
358+
result = self._get_axes_layout(_flatten(axes))
358359
self.assertEqual(result, layout)
359360

360361
self.assert_numpy_array_equal(
@@ -380,7 +381,7 @@ def _flatten_visible(self, axes):
380381
axes : matplotlib Axes object, or its list-like
381382
382383
"""
383-
axes = plotting.tools._flatten(axes)
384+
axes = _flatten(axes)
384385
axes = [ax for ax in axes if ax.get_visible()]
385386
return axes
386387

pandas/tests/plotting/test_boxplot_method.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ def test_boxplot_legacy(self):
5454
_check_plot_works(df.boxplot, by='indic')
5555
with tm.assert_produces_warning(UserWarning):
5656
_check_plot_works(df.boxplot, by=['indic', 'indic2'])
57-
_check_plot_works(plotting.boxplot, data=df['one'], return_type='dict')
57+
_check_plot_works(plotting._core.boxplot, data=df['one'],
58+
return_type='dict')
5859
_check_plot_works(df.boxplot, notch=1, return_type='dict')
5960
with tm.assert_produces_warning(UserWarning):
6061
_check_plot_works(df.boxplot, by='indic', notch=1)

pandas/tests/plotting/test_datetimelike.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_high_freq(self):
144144
_check_plot_works(ser.plot)
145145

146146
def test_get_datevalue(self):
147-
from pandas.plotting.converter import get_datevalue
147+
from pandas.plotting._converter import get_datevalue
148148
self.assertIsNone(get_datevalue(None, 'D'))
149149
self.assertEqual(get_datevalue(1987, 'A'), 1987)
150150
self.assertEqual(get_datevalue(Period(1987, 'A'), 'M'),
@@ -243,7 +243,7 @@ def test_plot_multiple_inferred_freq(self):
243243

244244
@slow
245245
def test_uhf(self):
246-
import pandas.plotting.converter as conv
246+
import pandas.plotting._converter as conv
247247
import matplotlib.pyplot as plt
248248
fig = plt.gcf()
249249
plt.clf()
@@ -387,7 +387,7 @@ def _test(ax):
387387
_test(ax)
388388

389389
def test_get_finder(self):
390-
import pandas.plotting.converter as conv
390+
import pandas.plotting._converter as conv
391391

392392
self.assertEqual(conv.get_finder('B'), conv._daily_finder)
393393
self.assertEqual(conv.get_finder('D'), conv._daily_finder)

pandas/tests/plotting/test_deprecated.py

-9
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,6 @@ def test_boxplot_deprecated(self):
4747
plotting.boxplot(df, column=['one', 'two'],
4848
by='indic')
4949

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-
5950
@slow
6051
def test_radviz_deprecated(self):
6152
df = self.iris

pandas/tests/plotting/test_frame.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -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.core._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.core._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.core._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.core._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.core._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_hist_method.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import numpy as np
1010
from numpy.random import randn
1111

12-
import pandas.plotting as plotting
12+
from pandas.plotting._core import grouped_hist
1313
from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works)
1414

1515

@@ -260,7 +260,7 @@ def test_grouped_hist_legacy(self):
260260
df['C'] = np.random.randint(0, 4, 500)
261261
df['D'] = ['X'] * 500
262262

263-
axes = plotting.grouped_hist(df.A, by=df.C)
263+
axes = grouped_hist(df.A, by=df.C)
264264
self._check_axes_shape(axes, axes_num=4, layout=(2, 2))
265265

266266
tm.close()
@@ -277,10 +277,9 @@ def test_grouped_hist_legacy(self):
277277
# make sure kwargs to hist are handled
278278
xf, yf = 20, 18
279279
xrot, yrot = 30, 40
280-
axes = plotting.grouped_hist(df.A, by=df.C, normed=True,
281-
cumulative=True, bins=4,
282-
xlabelsize=xf, xrot=xrot,
283-
ylabelsize=yf, yrot=yrot)
280+
axes = grouped_hist(df.A, by=df.C, normed=True, cumulative=True,
281+
bins=4, xlabelsize=xf, xrot=xrot,
282+
ylabelsize=yf, yrot=yrot)
284283
# height of last bin (index 5) must be 1.0
285284
for ax in axes.ravel():
286285
rects = [x for x in ax.get_children() if isinstance(x, Rectangle)]
@@ -290,14 +289,14 @@ def test_grouped_hist_legacy(self):
290289
ylabelsize=yf, yrot=yrot)
291290

292291
tm.close()
293-
axes = plotting.grouped_hist(df.A, by=df.C, log=True)
292+
axes = grouped_hist(df.A, by=df.C, log=True)
294293
# scale of y must be 'log'
295294
self._check_ax_scales(axes, yaxis='log')
296295

297296
tm.close()
298297
# propagate attr exception from matplotlib.Axes.hist
299298
with tm.assertRaises(AttributeError):
300-
plotting.grouped_hist(df.A, by=df.C, foo='bar')
299+
grouped_hist(df.A, by=df.C, foo='bar')
301300

302301
with tm.assert_produces_warning(FutureWarning):
303302
df.hist(by='C', figsize='default')

pandas/tests/plotting/test_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def scat(**kwds):
8484
_check_plot_works(scat, facecolor='rgb')
8585

8686
def scat2(x, y, by=None, ax=None, figsize=None):
87-
return plotting.scatter_plot(df, x, y, by, ax, figsize=None)
87+
return plotting._core.scatter_plot(df, x, y, by, ax, figsize=None)
8888

8989
_check_plot_works(scat2, x=0, y=1)
9090
grouper = Series(np.repeat([1, 2, 3, 4, 5], 20), df.index)

0 commit comments

Comments
 (0)