Skip to content

Commit

Permalink
Move tests upder plotting and other corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
sinhrks committed Jan 21, 2017
1 parent c545273 commit 2c4d7d0
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 43 deletions.
8 changes: 6 additions & 2 deletions pandas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pandas/plotting/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
# 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

from pandas.plotting.misc import (scatter_matrix, radviz,
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
from pandas.plotting.tools import table
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
68 changes: 68 additions & 0 deletions pandas/plotting/tests/test_deprecated.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand All @@ -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)

Expand All @@ -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)


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
21 changes: 21 additions & 0 deletions pandas/tools/plotting.py
Original file line number Diff line number Diff line change
@@ -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))
Loading

0 comments on commit 2c4d7d0

Please sign in to comment.