Skip to content

move late imports to top #26750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jun 11, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
import warnings

from matplotlib import pyplot as plt
from matplotlib.artist import setp
import numpy as np

from pandas.core.dtypes.generic import ABCSeries
from pandas.core.dtypes.missing import remove_na_arraylike
from pandas.core.reshape.concat import concat
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import from pandas

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just updated it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jreback I still pretty new here. Can I ask why this place could directly use import from pandas not import as previously ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previously before @datapythonista reorg (just merged)
the plotting code was basically imported during pandas init
and the pandas namespace was not fully defined yet

it’s now essentially decoupled from that so that it a lazy import
this we can use top of module imports rather than import into each function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Appreciated for this detail explanation. This is helpful.

from pandas.core.series import Series
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Series as well


from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
Expand Down Expand Up @@ -105,15 +108,13 @@ def maybe_color_bp(self, bp):
medians = self.color or self._medians_c
caps = self.color or self._caps_c

from matplotlib.artist import setp
setp(bp['boxes'], color=boxes, alpha=1)
setp(bp['whiskers'], color=whiskers, alpha=1)
setp(bp['medians'], color=medians, alpha=1)
setp(bp['caps'], color=caps, alpha=1)

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

for i, (label, y) in enumerate(self._iter_data()):
Expand Down Expand Up @@ -197,7 +198,6 @@ def _grouped_plot_by_column(plotf, data, columns=None, by=None,
ax_values.append(re_plotf)
ax.grid(grid)

from pandas.core.series import Series
result = Series(ax_values, index=columns)

# Return axes in multiplot case, maybe revisit later # 985
Expand Down Expand Up @@ -230,7 +230,6 @@ def _get_colors():

def maybe_color_bp(bp):
if 'color' not in kwds:
from matplotlib.artist import setp
setp(bp['boxes'], color=colors[0], alpha=1)
setp(bp['whiskers'], color=colors[0], alpha=1)
setp(bp['medians'], color=colors[2], alpha=1)
Expand Down Expand Up @@ -314,7 +313,6 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
figsize=figsize, layout=layout)
axes = _flatten(axes)

from pandas.core.series import Series
ret = Series()
for (key, group), ax in zip(grouped, axes):
d = group.boxplot(ax=ax, column=column, fontsize=fontsize,
Expand All @@ -324,7 +322,6 @@ def boxplot_frame_groupby(grouped, subplots=True, column=None, fontsize=None,
fig.subplots_adjust(bottom=0.15, top=0.9, left=0.1,
right=0.9, wspace=0.2)
else:
from pandas.core.reshape.concat import concat
keys, frames = zip(*grouped)
if grouped.axis == 0:
df = concat(frames, keys=keys, axis=1)
Expand Down