Skip to content

Commit 6f60ff8

Browse files
committed
Avoid circular import between core.series and plotting._xyz
This follows up on pandas-dev#16913 but cuts down on the scope of the PR.
1 parent 6000c5b commit 6f60ff8

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

pandas/core/series.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@
7777
from pandas._libs import index as libindex, tslib as libts, lib, iNaT
7878
from pandas.core.config import get_option
7979

80+
import pandas.plotting._core as _gfx # noqa
81+
8082
__all__ = ['Series']
8183

8284
_shared_doc_kwargs = dict(
@@ -3067,8 +3069,6 @@ def create_from_value(value, index, dtype):
30673069
# ----------------------------------------------------------------------
30683070
# Add plotting methods to Series
30693071

3070-
import pandas.plotting._core as _gfx # noqa
3071-
30723072
Series.plot = base.AccessorProperty(_gfx.SeriesPlotMethods,
30733073
_gfx.SeriesPlotMethods)
30743074
Series.hist = _gfx.hist_series

pandas/plotting/_core.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from pandas.util._decorators import cache_readonly
1313
from pandas.core.base import PandasObject
14+
from pandas.core.dtypes.generic import ABCSeries
1415
from pandas.core.dtypes.missing import notnull
1516
from pandas.core.dtypes.common import (
1617
is_list_like,
@@ -21,7 +22,6 @@
2122
from pandas.core.common import AbstractMethodError, isnull, _try_sort
2223
from pandas.core.generic import _shared_docs, _shared_doc_kwargs
2324
from pandas.core.index import Index, MultiIndex
24-
from pandas.core.series import Series, remove_na
2525
from pandas.core.indexes.period import PeriodIndex
2626
from pandas.compat import range, lrange, map, zip, string_types
2727
import pandas.compat as compat
@@ -334,7 +334,7 @@ def result(self):
334334
def _compute_plot_data(self):
335335
data = self.data
336336

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

1379+
from pandas.core.series import remove_na
13791380
y = remove_na(y)
13801381

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

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

15671569
def _make_plot(self):
15681570
if self.subplots:
1571+
from pandas import Series
15691572
self._return_obj = Series()
15701573

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

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

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

23892394
_axes = _flatten(axes)
23902395

2396+
from pandas import Series
23912397
result = Series()
23922398
ax_values = []
23932399

pandas/plotting/_tools.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from pandas.core.dtypes.common import is_list_like
1111
from pandas.core.index import Index
12-
from pandas.core.series import Series
1312
from pandas.compat import range
1413

1514

@@ -44,7 +43,7 @@ def table(ax, data, rowLabels=None, colLabels=None,
4443
-------
4544
matplotlib table object
4645
"""
47-
from pandas import DataFrame
46+
from pandas import Series, DataFrame
4847
if isinstance(data, Series):
4948
data = DataFrame(data, columns=[data.name])
5049
elif isinstance(data, DataFrame):

0 commit comments

Comments
 (0)