Skip to content

CLN: rename private functions used across modules #36049

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 35 commits into from
Sep 2, 2020
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4c5eddd
REF: remove unnecesary try/except
jbrockmendel Aug 21, 2020
c632c9f
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
9e64be3
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Aug 21, 2020
42649fb
TST: add test for agg on ordered categorical cols (#35630)
mathurk1 Aug 21, 2020
47121dd
TST: resample does not yield empty groups (#10603) (#35799)
tkmz-n Aug 21, 2020
1decb3e
revert accidental rebase
jbrockmendel Aug 22, 2020
57c5dd3
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 22, 2020
a358463
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
ffa7ad7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 23, 2020
e5e98d4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
408db5a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 24, 2020
d3493cf
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
75a805a
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
9f61070
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 25, 2020
2d10f6e
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
3e20187
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 26, 2020
e27d07f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
c52bed4
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 27, 2020
b69d4d7
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
1c5f8fd
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
061c9e2
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 28, 2020
0129a83
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
4d0d8e8
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
715848f
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 30, 2020
01f9c50
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
5f4f7dc
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
4f1f4e1
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
aa7d119
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
1f783d1
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Aug 31, 2020
7def723
Merge branch 'master' of https://github.com/pandas-dev/pandas into ma…
jbrockmendel Sep 1, 2020
60ca29f
de-privatize
jbrockmendel Sep 1, 2020
1c85e2c
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Sep 1, 2020
2a1eda4
docstring inside class, isort fixup
jbrockmendel Sep 1, 2020
98cbd66
Merge branch 'master' of https://github.com/pandas-dev/pandas into re…
jbrockmendel Sep 2, 2020
3270e2b
typo fixup
jbrockmendel Sep 2, 2020
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
16 changes: 8 additions & 8 deletions pandas/plotting/_matplotlib/boxplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

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
from pandas.plotting._matplotlib.tools import _flatten, _subplots
from pandas.plotting._matplotlib.style import get_standard_colors
from pandas.plotting._matplotlib.tools import create_subplots, flatten_axes

if TYPE_CHECKING:
from matplotlib.axes import Axes
Expand Down Expand Up @@ -84,7 +84,7 @@ def _validate_color_args(self):
self.color = None

# get standard colors for default
colors = _get_standard_colors(num_colors=3, colormap=self.colormap, color=None)
colors = get_standard_colors(num_colors=3, colormap=self.colormap, color=None)
# use 2 colors by default, for box/whisker and median
# flier colors isn't needed here
# because it can be specified by ``sym`` kw
Expand Down Expand Up @@ -200,11 +200,11 @@ def _grouped_plot_by_column(
by = [by]
columns = data._get_numeric_data().columns.difference(by)
naxes = len(columns)
fig, axes = _subplots(
fig, axes = create_subplots(
naxes=naxes, sharex=True, sharey=True, figsize=figsize, ax=ax, layout=layout
)

_axes = _flatten(axes)
_axes = flatten_axes(axes)

ax_values = []

Expand Down Expand Up @@ -259,7 +259,7 @@ def _get_colors():
# num_colors=3 is required as method maybe_color_bp takes the colors
# in positions 0 and 2.
# if colors not provided, use same defaults as DataFrame.plot.box
result = _get_standard_colors(num_colors=3)
result = get_standard_colors(num_colors=3)
result = np.take(result, [0, 0, 2])
result = np.append(result, "k")

Expand Down Expand Up @@ -414,7 +414,7 @@ def boxplot_frame_groupby(
):
if subplots is True:
naxes = len(grouped)
fig, axes = _subplots(
fig, axes = create_subplots(
naxes=naxes,
squeeze=False,
ax=ax,
Expand All @@ -423,7 +423,7 @@ def boxplot_frame_groupby(
figsize=figsize,
layout=layout,
)
axes = _flatten(axes)
axes = flatten_axes(axes)

ret = pd.Series(dtype=object)

Expand Down
24 changes: 12 additions & 12 deletions pandas/plotting/_matplotlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@
from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.compat import _mpl_ge_3_0_0
from pandas.plotting._matplotlib.converter import register_pandas_matplotlib_converters
from pandas.plotting._matplotlib.style import _get_standard_colors
from pandas.plotting._matplotlib.style import get_standard_colors
from pandas.plotting._matplotlib.tools import (
_flatten,
_get_all_lines,
_get_xlim,
_handle_shared_axes,
_subplots,
create_subplots,
flatten_axes,
format_date_labels,
get_all_lines,
get_xlim,
handle_shared_axes,
table,
)

Expand Down Expand Up @@ -315,7 +315,7 @@ def _maybe_right_yaxis(self, ax: "Axes", axes_num):

def _setup_subplots(self):
if self.subplots:
fig, axes = _subplots(
fig, axes = create_subplots(
naxes=self.nseries,
sharex=self.sharex,
sharey=self.sharey,
Expand All @@ -334,7 +334,7 @@ def _setup_subplots(self):
fig.set_size_inches(self.figsize)
axes = self.ax

axes = _flatten(axes)
axes = flatten_axes(axes)

valid_log = {False, True, "sym", None}
input_log = {self.logx, self.logy, self.loglog}
Expand Down Expand Up @@ -466,7 +466,7 @@ def _adorn_subplots(self):
if len(self.axes) > 0:
all_axes = self._get_subplots()
nrows, ncols = self._get_axes_layout()
_handle_shared_axes(
handle_shared_axes(
axarr=all_axes,
nplots=len(all_axes),
naxes=nrows * ncols,
Expand Down Expand Up @@ -753,7 +753,7 @@ def _get_colors(self, num_colors=None, color_kwds="color"):
if num_colors is None:
num_colors = self.nseries

return _get_standard_colors(
return get_standard_colors(
num_colors=num_colors,
colormap=self.colormap,
color=self.kwds.get(color_kwds),
Expand Down Expand Up @@ -1132,8 +1132,8 @@ def _make_plot(self):

# reset of xlim should be used for ts data
# TODO: GH28021, should find a way to change view limit on xaxis
lines = _get_all_lines(ax)
left, right = _get_xlim(lines)
lines = get_all_lines(ax)
left, right = get_xlim(lines)
ax.set_xlim(left, right)

@classmethod
Expand Down
20 changes: 12 additions & 8 deletions pandas/plotting/_matplotlib/hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.core import LinePlot, MPLPlot
from pandas.plotting._matplotlib.tools import _flatten, _set_ticks_props, _subplots
from pandas.plotting._matplotlib.tools import (
create_subplots,
flatten_axes,
set_ticks_props,
)

if TYPE_CHECKING:
from matplotlib.axes import Axes
Expand Down Expand Up @@ -198,11 +202,11 @@ def _grouped_plot(
grouped = grouped[column]

naxes = len(grouped)
fig, axes = _subplots(
fig, axes = create_subplots(
naxes=naxes, figsize=figsize, sharex=sharex, sharey=sharey, ax=ax, layout=layout
)

_axes = _flatten(axes)
_axes = flatten_axes(axes)

for i, (key, group) in enumerate(grouped):
ax = _axes[i]
Expand Down Expand Up @@ -286,7 +290,7 @@ def plot_group(group, ax):
rot=rot,
)

_set_ticks_props(
set_ticks_props(
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
)

Expand Down Expand Up @@ -337,7 +341,7 @@ def hist_series(
ax.grid(grid)
axes = np.array([ax])

_set_ticks_props(
set_ticks_props(
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
)

Expand Down Expand Up @@ -419,7 +423,7 @@ def hist_frame(
if naxes == 0:
raise ValueError("hist method requires numerical columns, nothing to plot.")

fig, axes = _subplots(
fig, axes = create_subplots(
naxes=naxes,
ax=ax,
squeeze=False,
Expand All @@ -428,7 +432,7 @@ def hist_frame(
figsize=figsize,
layout=layout,
)
_axes = _flatten(axes)
_axes = flatten_axes(axes)

can_set_label = "label" not in kwds

Expand All @@ -442,7 +446,7 @@ def hist_frame(
if legend:
ax.legend()

_set_ticks_props(
set_ticks_props(
axes, xlabelsize=xlabelsize, xrot=xrot, ylabelsize=ylabelsize, yrot=yrot
)
fig.subplots_adjust(wspace=0.3, hspace=0.3)
Expand Down
14 changes: 7 additions & 7 deletions pandas/plotting/_matplotlib/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from pandas.core.dtypes.missing import notna

from pandas.io.formats.printing import pprint_thing
from pandas.plotting._matplotlib.style import _get_standard_colors
from pandas.plotting._matplotlib.tools import _set_ticks_props, _subplots
from pandas.plotting._matplotlib.style import get_standard_colors
from pandas.plotting._matplotlib.tools import create_subplots, set_ticks_props

if TYPE_CHECKING:
from matplotlib.axes import Axes
Expand All @@ -36,7 +36,7 @@ def scatter_matrix(
df = frame._get_numeric_data()
n = df.columns.size
naxes = n * n
fig, axes = _subplots(naxes=naxes, figsize=figsize, ax=ax, squeeze=False)
fig, axes = create_subplots(naxes=naxes, figsize=figsize, ax=ax, squeeze=False)

# no gaps between subplots
fig.subplots_adjust(wspace=0, hspace=0)
Expand Down Expand Up @@ -112,7 +112,7 @@ def scatter_matrix(
locs = locs.astype(int)
axes[0][0].yaxis.set_ticklabels(locs)

_set_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)
set_ticks_props(axes, xlabelsize=8, xrot=90, ylabelsize=8, yrot=0)

return axes

Expand Down Expand Up @@ -147,7 +147,7 @@ def normalize(series):
ax = plt.gca(xlim=[-1, 1], ylim=[-1, 1])

to_plot: Dict[Label, List[List]] = {}
colors = _get_standard_colors(
colors = get_standard_colors(
num_colors=len(classes), colormap=colormap, color_type="random", color=color
)

Expand Down Expand Up @@ -255,7 +255,7 @@ def f(t):
t = np.linspace(-np.pi, np.pi, samples)
used_legends: Set[str] = set()

color_values = _get_standard_colors(
color_values = get_standard_colors(
num_colors=len(classes), colormap=colormap, color_type="random", color=color
)
colors = dict(zip(classes, color_values))
Expand Down Expand Up @@ -382,7 +382,7 @@ def parallel_coordinates(
if ax is None:
ax = plt.gca()

color_values = _get_standard_colors(
color_values = get_standard_colors(
num_colors=len(classes), colormap=colormap, color_type="random", color=color
)

Expand Down
2 changes: 1 addition & 1 deletion pandas/plotting/_matplotlib/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pandas.core.common as com


def _get_standard_colors(
def get_standard_colors(
num_colors=None, colormap=None, color_type: str = "default", color=None
):
import matplotlib.pyplot as plt
Expand Down
20 changes: 10 additions & 10 deletions pandas/plotting/_matplotlib/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _get_layout(nplots: int, layout=None, layout_type: str = "box") -> Tuple[int
# copied from matplotlib/pyplot.py and modified for pandas.plotting


def _subplots(
def create_subplots(
naxes: int,
sharex: bool = False,
sharey: bool = False,
Expand Down Expand Up @@ -194,7 +194,7 @@ def _subplots(
fig = plt.figure(**fig_kw)
else:
if is_list_like(ax):
ax = _flatten(ax)
ax = flatten_axes(ax)
if layout is not None:
warnings.warn(
"When passing multiple axes, layout keyword is ignored", UserWarning
Expand All @@ -221,7 +221,7 @@ def _subplots(
if squeeze:
return fig, ax
else:
return fig, _flatten(ax)
return fig, flatten_axes(ax)
else:
warnings.warn(
"To output multiple subplots, the figure containing "
Expand Down Expand Up @@ -264,7 +264,7 @@ def _subplots(
for ax in axarr[naxes:]:
ax.set_visible(False)

_handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey)
handle_shared_axes(axarr, nplots, naxes, nrows, ncols, sharex, sharey)

if squeeze:
# Reshape the array to have the final desired dimension (nrow,ncol),
Expand Down Expand Up @@ -297,7 +297,7 @@ def _remove_labels_from_axis(axis: "Axis"):
axis.get_label().set_visible(False)


def _handle_shared_axes(
def handle_shared_axes(
axarr: Iterable["Axes"],
nplots: int,
naxes: int,
Expand Down Expand Up @@ -351,15 +351,15 @@ def _handle_shared_axes(
_remove_labels_from_axis(ax.yaxis)


def _flatten(axes: Union["Axes", Sequence["Axes"]]) -> Sequence["Axes"]:
def flatten_axes(axes: Union["Axes", Sequence["Axes"]]) -> Sequence["Axes"]:
if not is_list_like(axes):
return np.array([axes])
elif isinstance(axes, (np.ndarray, ABCIndexClass)):
return axes.ravel()
return np.array(axes)


def _set_ticks_props(
def set_ticks_props(
axes: Union["Axes", Sequence["Axes"]],
xlabelsize=None,
xrot=None,
Expand All @@ -368,7 +368,7 @@ def _set_ticks_props(
):
import matplotlib.pyplot as plt

for ax in _flatten(axes):
for ax in flatten_axes(axes):
if xlabelsize is not None:
plt.setp(ax.get_xticklabels(), fontsize=xlabelsize)
if xrot is not None:
Expand All @@ -380,7 +380,7 @@ def _set_ticks_props(
return axes


def _get_all_lines(ax: "Axes") -> List["Line2D"]:
def get_all_lines(ax: "Axes") -> List["Line2D"]:
lines = ax.get_lines()

if hasattr(ax, "right_ax"):
Expand All @@ -392,7 +392,7 @@ def _get_all_lines(ax: "Axes") -> List["Line2D"]:
return lines


def _get_xlim(lines: Iterable["Line2D"]) -> Tuple[float, float]:
def get_xlim(lines: Iterable["Line2D"]) -> Tuple[float, float]:
left, right = np.inf, -np.inf
for l in lines:
x = l.get_xdata(orig=False)
Expand Down
9 changes: 5 additions & 4 deletions pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pandas import DataFrame, Series
import pandas._testing as tm


"""
This is a common base class used for various plotting tests
"""
Copy link
Member

Choose a reason for hiding this comment

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

does this docstring belong inside the following class

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, updated

Expand Down Expand Up @@ -330,7 +331,7 @@ def _check_axes_shape(self, axes, axes_num=None, layout=None, figsize=None):
figsize : tuple
expected figsize. default is matplotlib default
"""
from pandas.plotting._matplotlib.tools import _flatten
from pandas.plotting._matplotlib.tools import flatten_axes

if figsize is None:
figsize = self.default_figsize
Expand All @@ -343,7 +344,7 @@ def _check_axes_shape(self, axes, axes_num=None, layout=None, figsize=None):
assert len(ax.get_children()) > 0

if layout is not None:
result = self._get_axes_layout(_flatten(axes))
result = self._get_axes_layout(flatten_axes(axes))
assert result == layout

tm.assert_numpy_array_equal(
Expand All @@ -370,9 +371,9 @@ def _flatten_visible(self, axes):
axes : matplotlib Axes object, or its list-like

"""
from pandas.plotting._matplotlib.tools import _flatten
from pandas.plotting._matplotlib.tools import flatten_axes

axes = _flatten(axes)
axes = flatten_axes(axes)
axes = [ax for ax in axes if ax.get_visible()]
return axes

Expand Down
Loading