From 2c4d7d08e47499d6ad497e55ef939e82ca77f0f2 Mon Sep 17 00:00:00 2001 From: sinhrks Date: Sat, 21 Jan 2017 10:23:57 +0900 Subject: [PATCH] Move tests upder plotting and other corrections --- pandas/__init__.py | 8 ++- pandas/core/frame.py | 2 +- pandas/core/groupby.py | 2 +- pandas/core/series.py | 2 +- pandas/plotting/api.py | 10 +-- pandas/plotting/{plotting.py => core.py} | 0 .../plotting => plotting/tests}/__init__.py | 0 .../plotting => plotting/tests}/common.py | 5 +- .../tests}/test_boxplot_method.py | 4 +- .../tests}/test_converter.py | 0 .../tests}/test_datetimelike.py | 2 +- pandas/plotting/tests/test_deprecated.py | 68 +++++++++++++++++++ .../plotting => plotting/tests}/test_frame.py | 12 ++-- .../tests}/test_groupby.py | 2 +- .../tests}/test_hist_method.py | 4 +- .../plotting => plotting/tests}/test_misc.py | 16 ++--- .../tests}/test_series.py | 16 ++--- pandas/plotting/timeseries.py | 2 +- pandas/tools/plotting.py | 21 ++++++ pandas/util/doctools.py | 2 +- setup.py | 4 +- 21 files changed, 139 insertions(+), 43 deletions(-) rename pandas/plotting/{plotting.py => core.py} (100%) rename pandas/{tests/plotting => plotting/tests}/__init__.py (100%) rename pandas/{tests/plotting => plotting/tests}/common.py (98%) rename pandas/{tests/plotting => plotting/tests}/test_boxplot_method.py (99%) rename pandas/{tests/plotting => plotting/tests}/test_converter.py (100%) rename pandas/{tests/plotting => plotting/tests}/test_datetimelike.py (99%) create mode 100644 pandas/plotting/tests/test_deprecated.py rename pandas/{tests/plotting => plotting/tests}/test_frame.py (99%) rename pandas/{tests/plotting => plotting/tests}/test_groupby.py (97%) rename pandas/{tests/plotting => plotting/tests}/test_hist_method.py (99%) rename pandas/{tests/plotting => plotting/tests}/test_misc.py (96%) rename pandas/{tests/plotting => plotting/tests}/test_series.py (98%) create mode 100644 pandas/tools/plotting.py diff --git a/pandas/__init__.py b/pandas/__init__.py index d86adb35ed3e05..ae27b514b74dca 100644 --- a/pandas/__init__.py +++ b/pandas/__init__.py @@ -47,9 +47,13 @@ merge_ordered, merge_asof) from pandas.tools.pivot import pivot_table, crosstab -# deprecated +# deprecate tools.plotting, and directly imported scatter_matrix import pandas.tools.plotting -from pandas.plotting import scatter_matrix, plot_params +from pandas.plotting import plot_params +from pandas.util.decorators import deprecate +scatter_matrix = deprecate('pandas.scatter_matrix', pandas.plotting.scatter_matrix, + 'pandas.plotting.scatter_matrix') + from pandas.tools.tile import cut, qcut from pandas.tools.util import to_numeric from pandas.core.reshape import melt diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 73badb97767267..0f5e5aae4aa2d7 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -90,7 +90,7 @@ import pandas.core.ops as ops import pandas.formats.format as fmt from pandas.formats.printing import pprint_thing -import pandas.plotting.plotting as gfx +import pandas.plotting.core as gfx import pandas.lib as lib import pandas.algos as _algos diff --git a/pandas/core/groupby.py b/pandas/core/groupby.py index fd3f53ee5e7535..7eced3c82c0e69 100644 --- a/pandas/core/groupby.py +++ b/pandas/core/groupby.py @@ -3997,7 +3997,7 @@ def count(self): return self._wrap_agged_blocks(data.items, list(blk)) -from pandas.plotting.plotting import boxplot_frame_groupby # noqa +from pandas.plotting.core import boxplot_frame_groupby # noqa DataFrameGroupBy.boxplot = boxplot_frame_groupby diff --git a/pandas/core/series.py b/pandas/core/series.py index 6979adabc7f88a..12da40d3372665 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -2997,7 +2997,7 @@ def __init__(self, *args, **kwargs): # ---------------------------------------------------------------------- # Add plotting methods to Series -import pandas.plotting.plotting as _gfx # noqa +import pandas.plotting.core as _gfx # noqa Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods, _gfx.SeriesPlotMethods) diff --git a/pandas/plotting/api.py b/pandas/plotting/api.py index a64792e4063577..f1df2e4426151e 100644 --- a/pandas/plotting/api.py +++ b/pandas/plotting/api.py @@ -5,8 +5,8 @@ # flake8: noqa try: # mpl optional - from pandas.plotting import converter as conv - conv.register() # needs to override so set_xlim works with str/number + from pandas.plotting import converter + converter.register() # needs to override so set_xlim works with str/number except ImportError: pass @@ -14,7 +14,7 @@ andrews_curves, bootstrap_plot, parallel_coordinates, lag_plot, autocorrelation_plot) -from pandas.plotting.plotting import (boxplot, scatter_plot, grouped_hist, - hist_frame, hist_series) +from pandas.plotting.core import (boxplot, scatter_plot, grouped_hist, + hist_frame, hist_series) from pandas.plotting.style import plot_params -from pandas.plotting.tools import table \ No newline at end of file +from pandas.plotting.tools import table diff --git a/pandas/plotting/plotting.py b/pandas/plotting/core.py similarity index 100% rename from pandas/plotting/plotting.py rename to pandas/plotting/core.py diff --git a/pandas/tests/plotting/__init__.py b/pandas/plotting/tests/__init__.py similarity index 100% rename from pandas/tests/plotting/__init__.py rename to pandas/plotting/tests/__init__.py diff --git a/pandas/tests/plotting/common.py b/pandas/plotting/tests/common.py similarity index 98% rename from pandas/tests/plotting/common.py rename to pandas/plotting/tests/common.py index 5efd9509e540b5..c4504321913706 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/plotting/tests/common.py @@ -72,7 +72,10 @@ def setUp(self): self.default_tick_position = 'left' if self.mpl_ge_2_0_0 else 'default' # common test data from pandas import read_csv - path = os.path.join(os.path.dirname(curpath()), 'data', 'iris.csv') + base = os.path.split(os.path.dirname(curpath()))[:-1] + print(os.path.dirname(curpath()), base) + path = os.path.join(*base, + 'tests', 'data', 'iris.csv') self.iris = read_csv(path) n = 100 diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/plotting/tests/test_boxplot_method.py similarity index 99% rename from pandas/tests/plotting/test_boxplot_method.py rename to pandas/plotting/tests/test_boxplot_method.py index 289d48ba6d4cca..993daaf91ef721 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/plotting/tests/test_boxplot_method.py @@ -14,9 +14,9 @@ from numpy import random from numpy.random import randn -import pandas.tools.plotting as plotting +import pandas.plotting as plotting -from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works) +from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works) """ Test cases for .boxplot method """ diff --git a/pandas/tests/plotting/test_converter.py b/pandas/plotting/tests/test_converter.py similarity index 100% rename from pandas/tests/plotting/test_converter.py rename to pandas/plotting/tests/test_converter.py diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/plotting/tests/test_datetimelike.py similarity index 99% rename from pandas/tests/plotting/test_datetimelike.py rename to pandas/plotting/tests/test_datetimelike.py index b0789458a32f1f..a36cbd228b79c1 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/plotting/tests/test_datetimelike.py @@ -14,7 +14,7 @@ from pandas.util.testing import assert_series_equal, ensure_clean, slow import pandas.util.testing as tm -from pandas.tests.plotting.common import (TestPlotBase, +from pandas.plotting.tests.common import (TestPlotBase, _skip_if_no_scipy_gaussian_kde) diff --git a/pandas/plotting/tests/test_deprecated.py b/pandas/plotting/tests/test_deprecated.py new file mode 100644 index 00000000000000..59434ec813f2b0 --- /dev/null +++ b/pandas/plotting/tests/test_deprecated.py @@ -0,0 +1,68 @@ +# coding: utf-8 + +import nose +import string + +import pandas as pd +import pandas.util.testing as tm +from pandas.util.testing import slow + +import numpy as np +from numpy.random import randn + +import pandas.tools.plotting as plotting + +from pandas.plotting.tests.common import TestPlotBase + + +""" +Test cases for plot functions imported from deprecated +pandas.tools.plotting +""" + + +@tm.mplskip +class TestDeprecatedNameSpace(TestPlotBase): + + @slow + def test_scatter_plot_legacy(self): + tm._skip_if_no_scipy() + + df = pd.DataFrame(randn(100, 2)) + + with tm.assert_produces_warning(FutureWarning): + plotting.scatter_matrix(df) + + with tm.assert_produces_warning(FutureWarning): + pd.scatter_matrix(df) + + @slow + def test_boxplot_deprecated(self): + df = pd.DataFrame(randn(6, 4), + index=list(string.ascii_letters[:6]), + columns=['one', 'two', 'three', 'four']) + df['indic'] = ['foo', 'bar'] * 3 + + with tm.assert_produces_warning(FutureWarning): + plotting.boxplot(df, column=['one', 'two'], + by='indic') + + @slow + def test_grouped_hist_legacy(self): + df = pd.DataFrame(randn(500, 2), columns=['A', 'B']) + df['C'] = np.random.randint(0, 4, 500) + df['D'] = ['X'] * 500 + + with tm.assert_produces_warning(FutureWarning): + plotting.grouped_hist(df.A, by=df.C) + + @slow + def test_radviz_deprecated(self): + df = self.iris + with tm.assert_produces_warning(FutureWarning): + plotting.radviz(frame=df, class_column='Name') + + +if __name__ == '__main__': + nose.runmodule(argv=[__file__, '-vvs', '-x', '--pdb', '--pdb-failure'], + exit=False) diff --git a/pandas/tests/plotting/test_frame.py b/pandas/plotting/tests/test_frame.py similarity index 99% rename from pandas/tests/plotting/test_frame.py rename to pandas/plotting/tests/test_frame.py index c4d2620cad04d2..79f9176fc58bf8 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/plotting/tests/test_frame.py @@ -21,7 +21,7 @@ from numpy.random import rand, randn import pandas.plotting as plotting -from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works, +from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works, _skip_if_no_scipy_gaussian_kde, _ok_for_gaussian_kde) @@ -1967,7 +1967,7 @@ def test_unordered_ts(self): def test_kind_both_ways(self): df = DataFrame({'x': [1, 2, 3]}) - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue df.plot(kind=kind) @@ -1978,7 +1978,7 @@ def test_kind_both_ways(self): def test_all_invalid_plot_data(self): df = DataFrame(list('abcd')) - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue with tm.assertRaises(TypeError): @@ -1989,7 +1989,7 @@ def test_partially_invalid_plot_data(self): with tm.RNGContext(42): df = DataFrame(randn(10, 2), dtype=object) df[np.random.rand(df.shape[0]) > 0.5] = 'a' - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue with tm.assertRaises(TypeError): @@ -2442,7 +2442,7 @@ def test_memory_leak(self): import gc results = {} - for kind in plotting.plotting._plot_klass.keys(): + for kind in plotting.core._plot_klass.keys(): if not _ok_for_gaussian_kde(kind): continue args = {} @@ -2641,7 +2641,7 @@ def test_df_grid_settings(self): # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792 self._check_grid_settings( DataFrame({'a': [1, 2, 3], 'b': [2, 3, 4]}), - plotting.plotting._dataframe_kinds, kws={'x': 'a', 'y': 'b'}) + plotting.core._dataframe_kinds, kws={'x': 'a', 'y': 'b'}) def test_option_mpl_style(self): with tm.assert_produces_warning(FutureWarning, diff --git a/pandas/tests/plotting/test_groupby.py b/pandas/plotting/tests/test_groupby.py similarity index 97% rename from pandas/tests/plotting/test_groupby.py rename to pandas/plotting/tests/test_groupby.py index 3c682fbfbb89e4..fc2ba897c396d4 100644 --- a/pandas/tests/plotting/test_groupby.py +++ b/pandas/plotting/tests/test_groupby.py @@ -7,7 +7,7 @@ import numpy as np -from pandas.tests.plotting.common import TestPlotBase +from pandas.plotting.tests.common import TestPlotBase """ Test cases for GroupBy.plot """ diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/plotting/tests/test_hist_method.py similarity index 99% rename from pandas/tests/plotting/test_hist_method.py rename to pandas/plotting/tests/test_hist_method.py index bde5544390b85b..3bab4570e6d88b 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/plotting/tests/test_hist_method.py @@ -9,8 +9,8 @@ import numpy as np from numpy.random import randn -import pandas.tools.plotting as plotting -from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works) +import pandas.plotting as plotting +from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works) """ Test cases for .hist method """ diff --git a/pandas/tests/plotting/test_misc.py b/pandas/plotting/tests/test_misc.py similarity index 96% rename from pandas/tests/plotting/test_misc.py rename to pandas/plotting/tests/test_misc.py index 2650ce2879db7a..1fb279e814a9f9 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/plotting/tests/test_misc.py @@ -11,8 +11,8 @@ from numpy import random from numpy.random import randn -import pandas.tools.plotting as plotting -from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works, +import pandas.plotting as plotting +from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works, _ok_for_gaussian_kde) """ Test cases for misc plot functions """ @@ -30,7 +30,7 @@ def setUp(self): @slow def test_autocorrelation_plot(self): - from pandas.tools.plotting import autocorrelation_plot + from pandas.plotting import autocorrelation_plot _check_plot_works(autocorrelation_plot, series=self.ts) _check_plot_works(autocorrelation_plot, series=self.ts.values) @@ -39,13 +39,13 @@ def test_autocorrelation_plot(self): @slow def test_lag_plot(self): - from pandas.tools.plotting import lag_plot + from pandas.plotting import lag_plot _check_plot_works(lag_plot, series=self.ts) _check_plot_works(lag_plot, series=self.ts, lag=5) @slow def test_bootstrap_plot(self): - from pandas.tools.plotting import bootstrap_plot + from pandas.plotting import bootstrap_plot _check_plot_works(bootstrap_plot, series=self.ts, size=10) @@ -124,7 +124,7 @@ def test_scatter_matrix_axis(self): @slow def test_andrews_curves(self): - from pandas.tools.plotting import andrews_curves + from pandas.plotting import andrews_curves from matplotlib import cm df = self.iris @@ -189,7 +189,7 @@ def test_andrews_curves(self): @slow def test_parallel_coordinates(self): - from pandas.tools.plotting import parallel_coordinates + from pandas.plotting import parallel_coordinates from matplotlib import cm df = self.iris @@ -237,7 +237,7 @@ def test_parallel_coordinates(self): @slow def test_radviz(self): - from pandas.tools.plotting import radviz + from pandas.plotting import radviz from matplotlib import cm df = self.iris diff --git a/pandas/tests/plotting/test_series.py b/pandas/plotting/tests/test_series.py similarity index 98% rename from pandas/tests/plotting/test_series.py rename to pandas/plotting/tests/test_series.py index dc63bb794f7927..b154ece2eadb08 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/plotting/tests/test_series.py @@ -15,7 +15,7 @@ from numpy.random import randn import pandas.plotting as plotting -from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works, +from pandas.plotting.tests.common import (TestPlotBase, _check_plot_works, _skip_if_no_scipy_gaussian_kde, _ok_for_gaussian_kde) @@ -623,8 +623,8 @@ def test_boxplot_series(self): @slow def test_kind_both_ways(self): s = Series(range(3)) - kinds = (plotting.plotting._common_kinds + - plotting.plotting._series_kinds) + kinds = (plotting.core._common_kinds + + plotting.core._series_kinds) for kind in kinds: if not _ok_for_gaussian_kde(kind): continue @@ -634,7 +634,7 @@ def test_kind_both_ways(self): @slow def test_invalid_plot_data(self): s = Series(list('abcd')) - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue with tm.assertRaises(TypeError): @@ -643,14 +643,14 @@ def test_invalid_plot_data(self): @slow def test_valid_object_plot(self): s = Series(lrange(10), dtype=object) - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue _check_plot_works(s.plot, kind=kind) def test_partially_invalid_plot_data(self): s = Series(['a', 'b', 1.0, 2]) - for kind in plotting.plotting._common_kinds: + for kind in plotting.core._common_kinds: if not _ok_for_gaussian_kde(kind): continue with tm.assertRaises(TypeError): @@ -721,8 +721,8 @@ def test_table(self): def test_series_grid_settings(self): # Make sure plot defaults to rcParams['axes.grid'] setting, GH 9792 self._check_grid_settings(Series([1, 2, 3]), - plotting.plotting._series_kinds + - plotting.plotting._common_kinds) + plotting.core._series_kinds + + plotting.core._common_kinds) @slow def test_standard_colors(self): diff --git a/pandas/plotting/timeseries.py b/pandas/plotting/timeseries.py index b88c46f448dd65..3f1cea1fb42a7c 100644 --- a/pandas/plotting/timeseries.py +++ b/pandas/plotting/timeseries.py @@ -131,7 +131,7 @@ def _replot_ax(ax, freq, kwargs): # for tsplot if isinstance(plotf, compat.string_types): - from pandas.plotting.plotting import _plot_klass + from pandas.plotting.core import _plot_klass plotf = _plot_klass[plotf]._plot lines.append(plotf(ax, series.index._mpl_repr(), diff --git a/pandas/tools/plotting.py b/pandas/tools/plotting.py new file mode 100644 index 00000000000000..c7d17760bbdbb4 --- /dev/null +++ b/pandas/tools/plotting.py @@ -0,0 +1,21 @@ +import sys +import warnings + +import pandas.plotting.api as api + +# back-compat of public API +# deprecate these functions +m = sys.modules['pandas.tools.plotting'] +for t in [t for t in dir(api) if not t.startswith('_')]: + + def outer(t=t): + + def wrapper(*args, **kwargs): + warnings.warn("pandas.tools.plotting.{t} is deprecated. " + "import from the " + "pandas.plotting.{t} instead".format(t=t), + FutureWarning, stacklevel=2) + return getattr(api, t)(*args, **kwargs) + return wrapper + + setattr(m, t, outer(t)) diff --git a/pandas/util/doctools.py b/pandas/util/doctools.py index 62dcba14055818..ff7236b4b78d34 100644 --- a/pandas/util/doctools.py +++ b/pandas/util/doctools.py @@ -131,7 +131,7 @@ def _make_table(self, ax, df, title, height=None): ax.set_visible(False) return - import pandas.tools.plotting as plotting + import pandas.plotting as plotting idx_nlevels = df.index.nlevels col_nlevels = df.columns.nlevels diff --git a/setup.py b/setup.py index 45b287bae4320e..1e0da7d06ca338 100755 --- a/setup.py +++ b/setup.py @@ -644,7 +644,6 @@ def pxd(name): 'pandas.tests.formats', 'pandas.tests.types', 'pandas.tests.test_msgpack', - 'pandas.tests.plotting', 'pandas.tools', 'pandas.tools.tests', 'pandas.tseries', @@ -657,7 +656,8 @@ def pxd(name): 'pandas.stats.tests', 'pandas.msgpack', 'pandas.util.clipboard', - 'pandas.plotting' + 'pandas.plotting', + 'pandas.plotting.tests' ], package_data={'pandas.io': ['tests/data/legacy_hdf/*.h5', 'tests/data/legacy_pickle/*/*.pickle',