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
Show file tree
Hide file tree
Changes from all commits
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
17 changes: 7 additions & 10 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
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

import pandas as pd

from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
from pandas.plotting._matplotlib.style import _get_standard_colors
Expand Down Expand Up @@ -105,16 +108,14 @@ 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()
self._return_obj = pd.Series()

for i, (label, y) in enumerate(self._iter_data()):
ax = self._get_ax(i)
Expand Down Expand Up @@ -197,8 +198,7 @@ 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)
result = pd.Series(ax_values, index=columns)

# Return axes in multiplot case, maybe revisit later # 985
if return_type is None:
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,8 +313,7 @@ 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()
ret = pd.Series()
for (key, group), ax in zip(grouped, axes):
d = group.boxplot(ax=ax, column=column, fontsize=fontsize,
rot=rot, grid=grid, **kwds)
Expand All @@ -324,10 +322,9 @@ 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)
df = pd.concat(frames, keys=keys, axis=1)
else:
if len(frames) > 1:
df = frames[0].join(frames[1::])
Expand Down
15 changes: 7 additions & 8 deletions pandas/plotting/_matplotlib/misc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# being a bit too dynamic
import random

import matplotlib.lines as mlines
import matplotlib.patches as patches
import matplotlib.pyplot as plt
import numpy as np

Expand Down Expand Up @@ -96,14 +99,12 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,


def _get_marker_compat(marker):
import matplotlib.lines as mlines
if marker not in mlines.lineMarkers:
return 'o'
return marker


def radviz(frame, class_column, ax=None, color=None, colormap=None, **kwds):
import matplotlib.patches as patches

def normalize(series):
a = min(series)
Expand Down Expand Up @@ -168,12 +169,11 @@ def normalize(series):

def andrews_curves(frame, class_column, ax=None, samples=200, color=None,
colormap=None, **kwds):
from math import sqrt, pi

def function(amplitudes):
def f(t):
x1 = amplitudes[0]
result = x1 / sqrt(2.0)
result = x1 / np.sqrt(2.0)

# Take the rest of the coefficients and resize them
# appropriately. Take a copy of amplitudes as otherwise numpy
Expand All @@ -196,15 +196,15 @@ def f(t):
class_col = frame[class_column]
classes = frame[class_column].drop_duplicates()
df = frame.drop(class_column, axis=1)
t = np.linspace(-pi, pi, samples)
t = np.linspace(-np.pi, np.pi, samples)
used_legends = set()

color_values = _get_standard_colors(num_colors=len(classes),
colormap=colormap, color_type='random',
color=color)
colors = dict(zip(classes, color_values))
if ax is None:
ax = plt.gca(xlim=(-pi, pi))
ax = plt.gca(xlim=(-np.pi, np.pi))
for i in range(n):
row = df.iloc[i].values
f = function(row)
Expand All @@ -223,7 +223,6 @@ def f(t):


def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
import random

# random.sample(ndarray, int) fails on python 3.3, sigh
data = list(series.values)
Expand Down
7 changes: 4 additions & 3 deletions pandas/plotting/_matplotlib/style.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# being a bit too dynamic
import warnings

import matplotlib.cm as cm
import matplotlib.colors
import matplotlib.pyplot as plt
import numpy as np

from pandas.core.dtypes.common import is_list_like

import pandas.core.common as com


def _get_standard_colors(num_colors=None, colormap=None, color_type='default',
color=None):
if color is None and colormap is not None:
if isinstance(colormap, str):
import matplotlib.cm as cm
cmap = colormap
colormap = cm.get_cmap(colormap)
if colormap is None:
Expand All @@ -37,7 +40,6 @@ def _get_standard_colors(num_colors=None, colormap=None, color_type='default',

colors = colors[0:num_colors]
elif color_type == 'random':
import pandas.core.common as com

def random_color(column):
""" Returns a random color represented as a list of length 3"""
Expand All @@ -50,7 +52,6 @@ def random_color(column):
raise ValueError("color_type must be either 'default' or 'random'")

if isinstance(colors, str):
import matplotlib.colors
conv = matplotlib.colors.ColorConverter()

def _maybe_valid_colors(colors):
Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODO: Use the fact that axis can have units to simplify the process

import functools
import warnings

from matplotlib import pylab
import matplotlib.pyplot as plt
Expand All @@ -25,7 +26,6 @@


def tsplot(series, plotf, ax=None, **kwargs):
import warnings
"""
Plots a Series on the given Matplotlib axes or the current axes

Expand Down
4 changes: 2 additions & 2 deletions pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import warnings

import matplotlib.pyplot as plt
import matplotlib.table
import matplotlib.ticker as ticker
import numpy as np

from pandas.core.dtypes.common import is_list_like
Expand Down Expand Up @@ -37,7 +39,6 @@ def table(ax, data, rowLabels=None, colLabels=None, **kwargs):

cellText = data.values

import matplotlib.table
table = matplotlib.table.table(ax, cellText=cellText,
rowLabels=rowLabels,
colLabels=colLabels, **kwargs)
Expand Down Expand Up @@ -260,7 +261,6 @@ def _remove_labels_from_axis(axis):
try:
# set_visible will not be effective if
# minor axis has NullLocator and NullFormattor (default)
import matplotlib.ticker as ticker
if isinstance(axis.get_minor_locator(), ticker.NullLocator):
axis.set_minor_locator(ticker.AutoLocator())
if isinstance(axis.get_minor_formatter(), ticker.NullFormatter):
Expand Down