Skip to content

Commit

Permalink
Avoid circular import between core.series and plotting._xyz
Browse files Browse the repository at this point in the history
This follows up on pandas-dev#16913 but cuts down on the scope of the PR.
  • Loading branch information
jbrockmendel committed Jul 14, 2017
1 parent 6000c5b commit 6f60ff8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
from pandas._libs import index as libindex, tslib as libts, lib, iNaT
from pandas.core.config import get_option

import pandas.plotting._core as _gfx # noqa

__all__ = ['Series']

_shared_doc_kwargs = dict(
Expand Down Expand Up @@ -3067,8 +3069,6 @@ def create_from_value(value, index, dtype):
# ----------------------------------------------------------------------
# Add plotting methods to Series

import pandas.plotting._core as _gfx # noqa

Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods,
_gfx.SeriesPlotMethods)
Series.hist = _gfx.hist_series
Expand Down
10 changes: 8 additions & 2 deletions pandas/plotting/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pandas.util._decorators import cache_readonly
from pandas.core.base import PandasObject
from pandas.core.dtypes.generic import ABCSeries
from pandas.core.dtypes.missing import notnull
from pandas.core.dtypes.common import (
is_list_like,
Expand All @@ -21,7 +22,6 @@
from pandas.core.common import AbstractMethodError, isnull, _try_sort
from pandas.core.generic import _shared_docs, _shared_doc_kwargs
from pandas.core.index import Index, MultiIndex
from pandas.core.series import Series, remove_na
from pandas.core.indexes.period import PeriodIndex
from pandas.compat import range, lrange, map, zip, string_types
import pandas.compat as compat
Expand Down Expand Up @@ -334,7 +334,7 @@ def result(self):
def _compute_plot_data(self):
data = self.data

if isinstance(data, Series):
if isinstance(data, ABCSeries):
label = self.label
if label is None and data.name is None:
label = 'None'
Expand Down Expand Up @@ -1376,6 +1376,7 @@ def _plot(cls, ax, y, style=None, bw_method=None, ind=None,
from scipy.stats import gaussian_kde
from scipy import __version__ as spv

from pandas.core.series import remove_na
y = remove_na(y)

if LooseVersion(spv) >= '0.11.0':
Expand Down Expand Up @@ -1494,6 +1495,7 @@ def _args_adjust(self):

@classmethod
def _plot(cls, ax, y, column_num=None, return_type='axes', **kwds):
from pandas.core.series import remove_na
if y.ndim == 2:
y = [remove_na(v) for v in y]
# Boxplot fails with empty arrays, so need to add a NaN
Expand Down Expand Up @@ -1566,6 +1568,7 @@ def maybe_color_bp(self, bp):

def _make_plot(self):
if self.subplots:
from pandas import Series
self._return_obj = Series()

for i, (label, y) in enumerate(self._iter_data()):
Expand Down Expand Up @@ -1968,6 +1971,7 @@ def maybe_color_bp(bp):
setp(bp['medians'], color=colors[2], alpha=1)

def plot_group(keys, values, ax):
from pandas.core.series import remove_na
keys = [pprint_thing(x) for x in keys]
values = [remove_na(v) for v in values]
bp = ax.boxplot(values, **kwds)
Expand Down Expand Up @@ -2317,6 +2321,7 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
figsize=figsize, layout=layout)
axes = _flatten(axes)

from pandas import Series
ret = Series()
for (key, group), ax in zip(grouped, axes):
d = group.boxplot(ax=ax, column=column, fontsize=fontsize,
Expand Down Expand Up @@ -2388,6 +2393,7 @@ def _grouped_plot_by_column(plotf, data, columns=None, by=None,

_axes = _flatten(axes)

from pandas import Series
result = Series()
ax_values = []

Expand Down
3 changes: 1 addition & 2 deletions pandas/plotting/_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from pandas.core.dtypes.common import is_list_like
from pandas.core.index import Index
from pandas.core.series import Series
from pandas.compat import range


Expand Down Expand Up @@ -44,7 +43,7 @@ def table(ax, data, rowLabels=None, colLabels=None,
-------
matplotlib table object
"""
from pandas import DataFrame
from pandas import Series, DataFrame
if isinstance(data, Series):
data = DataFrame(data, columns=[data.name])
elif isinstance(data, DataFrame):
Expand Down

0 comments on commit 6f60ff8

Please sign in to comment.