8000 Boring style fixes. by anntzer · Pull Request #11680 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Boring style fixes. #11680

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 1 commit into from
Jul 17, 2018
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
8 changes: 4 additions & 4 deletions examples/statistics/barchart_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ def attach_ordinal(num):
1 -> 1st
56 -> 56th
"""
suffixes = dict((str(i), v) for i, v in
enumerate(['th', 'st', 'nd', 'rd', 'th',
'th', 'th', 'th', 'th', 'th']))
suffixes = {str(i): v
for i, v in enumerate(['th', 'st', 'nd', 'rd', 'th',
'th', 'th', 'th', 'th', 'th'])}

v = str(num)
# special case early teens
Expand Down Expand Up @@ -170,7 +170,7 @@ def plot_student_results(student, scores, cohort_size):

rankStr = attach_ordinal(width)
# The bars aren't wide enough to print the ranking inside
if (width < 5):
if width < 5:
# Shift the text to the right side of the right edge
xloc = width + 1
# Black against white background
Expand Down
6 changes: 3 additions & 3 deletions examples/units/basic_units.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ def get_unit(self):
class UnitResolver(object):
def addition_rule(self, units):
for unit_1, unit_2 in zip(units[:-1], units[1:]):
if (unit_1 != unit_2):
if unit_1 != unit_2:
return NotImplemented
return units[0]

def multiplication_rule(self, units):
non_null = [u for u in units if u]
if (len(non_null) > 1):
if len(non_null) > 1:
return NotImplemented
return non_null[0]

Expand All @@ -268,7 +268,7 @@ def multiplication_rule(self, units):
'__rsub__': addition_rule}

def __call__(self, operation, units):
if (operation not in self.op_dict):
if operation not in self.op_dict:
return NotImplemented

return self.op_dict[operation](self, units)
Expand Down
11 changes: 6 additions & 5 deletions lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,16 @@ def set_linedash(self, offset, seq, store=1):
self.linedash = (offset, seq)

def set_font(self, fontname, fontsize, store=1):
if rcParams['ps.useafm']: return
if (fontname,fontsize) != (self.fontname,self.fontsize):
if rcParams['ps.useafm']:
return
if (fontname, fontsize) != (self.fontname,self.fontsize):
out = ("/%s findfont\n"
"%1.3f scalefont\n"
"setfont\n" % (fontname, fontsize))

self._pswriter.write(out)
if store: self.fontname = fontname
if store: self.fontsize = fontsize
if store:
self.fontname = fontname
self.fontsize = fontsize

def create_hatch(self, hatch):
sidelen = 72
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,7 @@ def delete_masked_points(*args):
"""
if not len(args):
return ()
if isinstance(args[0], str) or not iterable(args[0]):
if is_scalar_or_string(args[0]):
raise ValueError("First argument must be a sequence")
nrecs = len(args[0])
margs = []
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,7 @@ def set_verts(self, verts, closed=True):

def set_verts_and_codes(self, verts, codes):
'''This allows one to initialize vertices with path codes.'''
if (len(verts) != len(codes)):
if len(verts) != len(codes):
raise ValueError("'codes' must be a 1D list or array "
"with the same length of 'verts'")
self._paths = []
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,9 @@ def suptitle(self, t, **kwargs):
x = kwargs.pop('x', 0.5)
y = kwargs.pop('y', 0.98)

if ('horizontalalignment' not in kwargs) and ('ha' not in kwargs):
if 'horizontalalignment' not in kwargs and 'ha' not in kwargs:
kwargs['horizontalalignment'] = 'center'
if ('verticalalignment' not in kwargs) and ('va' not in kwargs):
if 'verticalalignment' not in kwargs and 'va' not in kwargs:
kwargs['verticalalignment'] = 'top'

if 'fontproperties' not in kwargs:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/gridspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def __init__(self, nrows, ncols, figure=None,
width_ratios=width_ratios,
height_ratios=height_ratios)

if (self.figure is None) or not self.figure.get_constrained_layout():
if self.figure is None or not self.figure.get_constrained_layout():
self._layoutbox = None
else:
self.figure.init_layoutbox()
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ def _get_legend_handles_labels(axs, legend_handler_map=None):

for handle in _get_legend_handles(axs, legend_handler_map):
label = handle.get_label()
if (label and not label.startswith('_')):
if label and not label.startswith('_'):
handles.append(handle)
labels.append(label)
return handles, labels
Expand Down
5 changes: 1 addition & 4 deletions lib/matplotlib/lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,7 @@ def get_markeredgewidth(self):
return self._markeredgewidth

def _get_markerfacecolor(self, alt=False):
if alt:
fc = self._markerfacecoloralt
else:
fc = self._markerfacecolor
fc = self._markerfacecoloralt if alt else self._markerfacecolor
if cbook._str_lower_equal(fc, 'auto'):
if self.get_fillstyle() == 'none':
return 'none'
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def __init__(self,
self._hatch_color = colors.to_rgba(mpl.rcParams['hatch.color'])
self._fill = True # needed for set_facecolor call
if color is not None:
if (edgecolor is not None or facecolor is not None):
if edgecolor is not None or facecolor is not None:
warnings.warn("Setting the 'color' property will override"
"the edgecolor or facecolor properties. ")
"the edgecolor or facecolor properties.")
self.set_color(color)
else:
self.set_edgecolor(edgecolor)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/path.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1,

if codes is not None:
codes = np.asarray(codes, self.code_type)
if (codes.ndim != 1) or len(codes) != len(vertices):
if codes.ndim != 1 or len(codes) != len(vertices):
raise ValueError("'codes' must be a 1D list or array with the "
"same length of 'vertices'")
if len(codes) and codes[0] != self.MOVETO:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ def test_wedge_movement():
'theta1': (0, 30, 'set_theta1'),
'theta2': (45, 50, 'set_theta2')}

init_args = dict((k, v[0]) for (k, v) in param_dict.items())
init_args = {k: v[0] for k, v in param_dict.items()}

w = mpatches.Wedge(**init_args)
for attr, (old_v, new_v, func) in param_dict.items():
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def test_two_2line_texts(spacing1, spacing2):

# line spacing only affects height
assert box1.width == box2.width
if (spacing1 == spacing2):
if spacing1 == spacing2:
assert box1.height == box2.height
else:
assert box1.height != box2.height
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2410,26 +2410,26 @@ def tick_values(self, vmin, vmax):
ticklocs = []
if decade_min <= -1:
expo = np.arange(decade_min, min(0, decade_max + 1))
ticklocs.extend(list(10**expo))
ticklocs.extend(10**expo)
if decade_min <= 0 <= decade_max:
ticklocs.append(0.5)
if decade_max >= 1:
expo = -np.arange(max(1, decade_min), decade_max + 1)
ticklocs.extend(list(1 - 10**expo))
ticklocs.extend(1 - 10**expo)

# minor ticks
else:
ticklocs = []
if decade_min <= -2:
expo = np.arange(decade_min, min(-1, decade_max))
newticks = np.outer(np.arange(2, 10), 10**expo).ravel()
ticklocs.extend(list(newticks))
ticklocs.extend(newticks)
if decade_min <= 0 <= decade_max:
ticklocs.extend([0.2, 0.3, 0.4, 0.6, 0.7, 0.8])
if decade_max >= 2:
expo = -np.arange(max(2, decade_min), decade_max + 1)
newticks = 1 - np.outer(np.arange(2, 10), 10**expo).ravel()
ticklocs.extend(list(newticks))
ticklocs.extend(newticks)

return self.raise_if_exceeds(np.array(ticklocs))

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/triinterpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def _interpolate_multikeys(self, x, y, tri_index=None,
if tri_index is None:
tri_index = self._trifinder(x, y)
else:
if (tri_index.shape != sh_ret):
if tri_index.shape != sh_ret:
raise ValueError(
"tri_index array is provided and shall"
" have same shape as x and y. Given: "
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _update(self, event):
event.canvas.release_mouse(self.ax)
return
val = self._value_in_bounds(event.xdata)
if (val is not None) and (val != self.val):
if val not in [None, self.val]:
self.set_val(val)

def set_val(self, val):
Expand Down Expand Up @@ -474,7 +474,7 @@ def disconnect(self, cid):

def reset(self):
"""Reset the slider to the initial value"""
if (self.val != self.valinit):
if self.val != self.valinit:
self.set_val(self.valinit)


Expand Down
2 changes: 1 addition & 1 deletion lib/mpl_toolkits/axes_grid1/axes_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def __init__(self, fig,
if ngrids is None:
ngrids = self._nrows * self._ncols
else:
if (ngrids > self._nrows * self._ncols) or (ngrids <= 0):
if not 0 < ngrids <= self._nrows * self._ncols:
raise Exception("")

self.ngrids = ngrids
Expand Down
10 changes: 5 additions & 5 deletions lib/mpl_toolkits/axisartist/axis_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def __init__(self, ticksize, tick_out=False, *, axis=None, **kwargs):
if self._axis is not None:
if "color" not in kwargs:
kwargs["color"] = "auto"
if ("mew" not in kwargs) and ("markeredgewidth" not in kwargs):
if "mew" not in kwargs and "markeredgewidth" not in kwargs:
kwargs["markeredgewidth"] = "auto"

Line2D.__init__(self, [0.], [0.], **kwargs)
Expand Down Expand Up @@ -1125,8 +1125,8 @@ def _draw_ticks(self, renderer):
self.minor_ticks.draw(renderer)
self.minor_ticklabels.draw(renderer)


if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()):
if (self.major_ticklabels.get_visible()
or self.minor_ticklabels.get_visible()):
self._draw_offsetText(renderer)

return extents
Expand Down Expand Up @@ -1169,8 +1169,8 @@ def _draw_ticks2(self, renderer):
self.minor_ticks.draw(renderer)
self.minor_ticklabels.draw(renderer)


if (self.major_ticklabels.get_visible() or self.minor_ticklabels.get_visible()):
if (self.major_ticklabels.get_visible()
or self.minor_ticklabels.get_visible()):
self._draw_offsetText(renderer)

return self.major_ticklabels.get_window_extents(renderer)
Expand Down
3 changes: 1 addition & 2 deletions lib/mpl_toolkits/axisartist/floating_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def get_axislabel_pos_angle(self, axes):
trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]])


if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.):
if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]])
xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy])
xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]])
Expand Down
3 changes: 1 addition & 2 deletions lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ def get_axislabel_pos_angle(self, axes):
trans_passingthrough_point = axes.transData + axes.transAxes.inverted()
p = trans_passingthrough_point.transform_point([xx1[0], yy1[0]])


if (0. <= p[0] <= 1.) and (0. <= p[1] <= 1.):
if 0 <= p[0] <= 1 and 0 <= p[1] <= 1:
xx1c, yy1c = axes.transData.transform_point([xx1[0], yy1[0]])
xx2, yy2 = grid_finder.transform_xy([xx0+dxx], [yy0+dyy])
xx2c, yy2c = axes.transData.transform_point([xx2[0], yy2[0]])
Expand Down
2 changes: 1 addition & 1 deletion setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def _check_for_pkg_config(self, package, include_file, min_version=None,
"Requires patches that have not been merged upstream.")

if min_version and version != 'unknown':
if (not is_min_version(version, min_version)):
if not is_min_version(version, min_version):
raise CheckFailed(
"Requires %s %s or later. Found %s." %
(package, min_version, version))
Expand Down
0