-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
move late imports to top #26750
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
830cf25
move late import to top
xcz011 e352331
fix isort check and import concat from pandas
xcz011 256a536
update imports for boxplot
xcz011 2caafc8
Move lazy imports to top for rest of _matplotlib
xcz011 a0a1d2a
restore scipy import back to function
xcz011 fcdc2d5
remove outdated comment
xcz011 c3863d5
switch pi sqrt import from math to numpy
xcz011 d95a9bf
restore scipy import back as lazy import
xcz011 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
from pandas.core.series import Series | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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()): | ||
|
@@ -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 | ||
|
@@ -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) | ||
|
@@ -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, | ||
|
@@ -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) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import from pandas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just updated it.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.