Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit de302f5

Browse files
committed
Call min/max directly on generator or two args.
1 parent 2ce3b61 commit de302f5

File tree

14 files changed

+59
-71
lines changed

14 files changed

+59
-71
lines changed

doc/utils/pylab_names.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@
4646

4747
print()
4848
funcs, docs = zip(*modd[mod])
49-
maxfunc = max([len(f) for f in funcs])
50-
maxdoc = max(40, max([len(d) for d in docs]) )
51-
border = ' '.join(['='*maxfunc, '='*maxdoc])
49+
maxfunc = max(len(f) for f in funcs)
50+
maxdoc = max(40, max(len(d) for d in docs))
51+
border = '=' * maxfunc + ' ' + '=' * maxdoc
5252
print(border)
53-
print(' '.join(['symbol'.ljust(maxfunc), 'description'.ljust(maxdoc)]))
53+
print('{:<{}} {:<{}}'.format('symbol', maxfunc, 'description', maxdoc))
5454
print(border)
5555
for func, doc in modd[mod]:
56-
row = ' '.join([func.ljust(maxfunc), doc.ljust(maxfunc)])
57-
print(row)
58-
56+
print('{:<{}} {:<{}}'.format(func, maxfunc, doc, maxdoc))
5957
print(border)
6058
print()
61-
#break

examples/axes_grid1/scatter_hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
# now determine nice limits by hand:
3232
binwidth = 0.25
33-
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))])
33+
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
3434
lim = (int(xymax/binwidth) + 1)*binwidth
3535

3636
bins = np.arange(-lim, lim + binwidth, binwidth)

examples/pylab_examples/scatter_hist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# now determine nice limits by hand:
3939
binwidth = 0.25
40-
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))])
40+
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
4141
lim = (int(xymax/binwidth) + 1) * binwidth
4242

4343
axScatter.set_xlim((-lim, lim))

examples/widgets/menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def __init__(self, fig, menuitems):
126126
self.menuitems = menuitems
127127
self.numitems = len(menuitems)
128128

129-
maxw = max([item.labelwidth for item in menuitems])
130-
maxh = max([item.labelheight for item in menuitems])
129+
maxw = max(item.labelwidth for item in menuitems)
130+
maxh = max(item.labelheight for item in menuitems)
131131

132132
totalh = self.numitems*maxh + (self.numitems + 1)*2*MenuItem.pady
133133

lib/matplotlib/artist.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,12 +1278,11 @@ def pprint_setters_rest(self, prop=None, leadingspace=2):
12781278

12791279
########
12801280
names = [self.aliased_name_rest(prop, target)
1281-
for prop, target
1282-
in attrs]
1281+
for prop, target in attrs]
12831282
accepts = [self.get_valid_values(prop) for prop, target in attrs]
12841283

1285-
col0_len = max([len(n) for n in names])
1286-
col1_len = max([len(a) for a in accepts])
1284+
col0_len = max(len(n) for n in names)
1285+
col1_len = max(len(a) for a in accepts)
12871286
table_formatstr = pad + '=' * col0_len + ' ' + '=' * col1_len
12881287

12891288
lines.append('')

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,17 +2162,17 @@ def make_iterable(x):
21622162

21632163
if adjust_xlim:
21642164
xmin, xmax = self.dataLim.intervalx
2165-
xmin = np.amin([w for w in width if w > 0])
2165+
xmin = np.min(w for w in width if w > 0)
21662166
if xerr is not None:
2167-
xmin = xmin - np.amax(xerr)
2167+
xmin = xmin - np.max(xerr)
21682168
xmin = max(xmin * 0.9, 1e-100)
21692169
self.dataLim.intervalx = (xmin, xmax)
21702170

21712171
if adjust_ylim:
21722172
ymin, ymax = self.dataLim.intervaly
2173-
ymin = np.amin([h for h in height if h > 0])
2173+
ymin = np.min(h for h in height if h > 0)
21742174
if yerr is not None:
2175-
ymin = ymin - np.amax(yerr)
2175+
ymin = ymin - np.max(yerr)
21762176
ymin = max(ymin * 0.9, 1e-100)
21772177
self.dataLim.intervaly = (ymin, ymax)
21782178
self.autoscale_view()

lib/matplotlib/mathtext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3183,8 +3183,8 @@ def overline(self, s, loc, toks):
31833183
def _auto_sized_delimiter(self, front, middle, back):
31843184
state = self.get_state()
31853185
if len(middle):
3186-
height = max([x.height for x in middle])
3187-
depth = max([x.depth for x in middle])
3186+
height = max(x.height for x in middle)
3187+
depth = max(x.depth for x in middle)
31883188
factor = None
31893189
else:
31903190
height = 0

lib/matplotlib/offsetbox.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ def _get_aligned_offsets(hd_list, height, align="baseline"):
119119
"""
120120

121121
if height is None:
122-
height = max([h for h, d in hd_list])
122+
height = max(h for h, d in hd_list)
123123

124124
if align == "baseline":
125-
height_descent = max([h - d for h, d in hd_list])
126-
descent = max([d for h, d in hd_list])
125+
height_descent = max(h - d for h, d in hd_list)
126+
descent = max(d for h, d in hd_list)
127127
height = height_descent + descent
128128
offsets = [0. for h, d in hd_list]
129129
elif align in ["left", "top"]:
@@ -465,8 +465,8 @@ def get_extent_offsets(self, renderer):
465465
return 2 * pad, 2 * pad, pad, pad, []
466466

467467
if self.height is None:
468-
height_descent = max([h - yd for w, h, xd, yd in whd_list])
469-
ydescent = max([yd for w, h, xd, yd in whd_list])
468+
height_descent = max(h - yd for w, h, xd, yd in whd_list)
469+
ydescent = max(yd for w, h, xd, yd in whd_list)
470470
height = height_descent + ydescent
471471
else:
472472
height = self.height - 2 * pad # width w/o pad

lib/matplotlib/patches.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,7 +1773,7 @@ def _pprint_table(_table, leadingspace=2):
17731773
for column, cell in zip(columns, row):
17741774
column.append(cell)
17751775

1776-
col_len = [max([len(cell) for cell in column]) for column in columns]
1776+
col_len = [max(len(cell) for cell in column) for column in columns]
17771777

17781778
lines = []
17791779
table_formatstr = pad + ' '.join([('=' * cl) for cl in col_len])
@@ -2050,8 +2050,8 @@ def transmute(self, x0, y0, width, height, mutation_size):
20502050

20512051
# boundary of the padded box
20522052
x0, y0 = x0 - pad, y0 - pad,
2053-
return Path.circle((x0 + width/2., y0 + height/2.),
2054-
(max([width, height]) / 2.))
2053+
return Path.circle((x0 + width / 2, y0 + height / 2),
2054+
max(width, height) / 2)
20552055

20562056
_style_list["circle"] = Circle
20572057

lib/matplotlib/ticker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1623,11 +1623,9 @@ def view_limits(self, vmin, vmax):
16231623
vmax += 1
16241624

16251625
if rcParams['axes.autolimit_mode'] == 'round_numbers':
1626-
exponent, remainder = _divmod(math.log10(vmax - vmin),
1627-
math.log10(max([self.numticks-1, 1])))
1628-
if remainder < 0.5:
1629-
exponent -= 1
1630-
scale = max([self.numticks-1, 1]) ** (-exponent)
1626+
exponent = round(math.log10(vmax - vmin)
1627+
/ math.log10(max(self.numticks - 1, 1))) - 1
1628+
scale = max(self.numticks - 1, 1) ** (-exponent)
16311629
vmin = math.floor(scale * vmin) / scale
16321630
vmax = math.ceil(scale * vmax) / scale
16331631

lib/matplotlib/tight_layout.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,18 @@ def auto_adjust_subplotpars(fig, renderer,
188188
top=1 - margin_top)
189189

190190
if cols > 1:
191-
hspace = max([sum(s)
192-
for i in range(rows)
193-
for s
194-
in hspaces[i * (cols + 1) + 1:(i + 1) * (cols + 1) - 1]])
195-
hspace += hpad_inches / fig_width_inch
196-
h_axes = ((1 - margin_right - margin_left) -
197-
hspace * (cols - 1)) / cols
198-
191+
hspace = (
192+
max(sum(s)
193+
for i in range(rows)
194+
for s in hspaces[i * (cols + 1) + 1:(i + 1) * (cols + 1) - 1])
195+
+ hpad_inches / fig_width_inch)
196+
h_axes = (1 - margin_right - margin_left - hspace * (cols - 1)) / cols
199197
kwargs["wspace"] = hspace / h_axes
200198

201199
if rows > 1:
202-
vspace = max([sum(s) for s in vspaces[cols:-cols]])
203-
vspace += vpad_inches / fig_height_inch
204-
v_axes = ((1 - margin_top - margin_bottom) -
205-
vspace * (rows - 1)) / rows
206-
200+
vspace = (max(sum(s) for s in vspaces[cols:-cols])
201+
+ vpad_inches / fig_height_inch)
202+
v_axes = (1 - margin_top - margin_bottom - vspace * (rows - 1)) / rows
207203
kwargs["hspace"] = vspace / v_axes
208204

209205
return kwargs

lib/matplotlib/transforms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,10 @@ def intersection(bbox1, bbox2):
761761
bbox2.ymax < bbox1.ymin)
762762

763763
if intersects:
764-
x0 = max([bbox1.xmin, bbox2.xmin])
765-
x1 = min([bbox1.xmax, bbox2.xmax])
766-
y0 = max([bbox1.ymin, bbox2.ymin])
767-
y1 = min([bbox1.ymax, bbox2.ymax])
764+
x0 = max(bbox1.xmin, bbox2.xmin)
765+
x1 = min(bbox1.xmax, bbox2.xmax)
766+
y0 = max(bbox1.ymin, bbox2.ymin)
767+
y1 = min(bbox1.ymax, bbox2.ymax)
768768
return Bbox.from_extents(x0, y0, x1, y1)
769769

770770
return None
@@ -2115,7 +2115,7 @@ def contains_branch_seperately(self, transform):
21152115

21162116
@property
21172117
def depth(self):
2118-
return max([self._x.depth, self._y.depth])
2118+
return max(self._x.depth, self._y.depth)
21192119

21202120
def contains_branch(self, other):
21212121
# a blended transform cannot possibly contain a branch from two different transforms.

lib/mpl_toolkits/axisartist/axis_artist.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -714,37 +714,37 @@ def _get_ticklabels_offsets(self, renderer, label_direction):
714714
va, ha = self.get_va(), self.get_ha()
715715

716716
if label_direction == "left":
717-
pad = max([w for (w, h, d) in whd_list])
717+
pad = max(w for w, h, d in whd_list)
718718
if ha == "left":
719719
r = pad
720720
elif ha == "center":
721721
r = .5 * pad
722722
elif label_direction == "right":
723-
pad = max([w for (w, h, d) in whd_list])
723+
pad = max(w for w, h, d in whd_list)
724724
if ha == "right":
725725
r = pad
726726
elif ha == "center":
727727
r = .5 * pad
728728
elif label_direction == "bottom":
729-
pad = max([h for (w, h, d) in whd_list])
729+
pad = max(h for w, h, d in whd_list)
730730
if va == "bottom":
731731
r = pad
732732
elif va == "center":
733733
r =.5 * pad
734734
elif va == "baseline":
735-
max_ascent = max([(h-d) for (w, h, d) in whd_list])
736-
max_descent = max([d for (w, h, d) in whd_list])
735+
max_ascent = max(h - d for w, h, d in whd_list)
736+
max_descent = max(d for w, h, d in whd_list)
737737
r = max_ascent
738738
pad = max_ascent + max_descent
739739
elif label_direction == "top":
740-
pad = max([h for (w, h, d) in whd_list])
740+
pad = max(h for w, h, d in whd_list)
741741
if va == "top":
742742
r = pad
743743
elif va == "center":
744744
r =.5 * pad
745745
elif va == "baseline":
746-
max_ascent = max([(h-d) for (w, h, d) in whd_list])
747-
max_descent = max([d for (w, h, d) in whd_list])
746+
max_ascent = max(h - d for w, h, d in whd_list)
747+
max_descent = max(d for w, h, d in whd_list)
748748
r = max_descent
749749
pad = max_ascent + max_descent
750750

@@ -1432,16 +1432,16 @@ def _update_label(self, renderer):
14321432

14331433
#print self._ticklabel_add_angle - self._axislabel_add_angle
14341434
#if abs(self._ticklabel_add_angle - self._axislabel_add_angle)%360 > 90:
1435-
if self._ticklabel_add_angle != self._axislabel_add_angle:
1435+
if self._ticklabel_add_angle != self._axislabel_add_angle:
14361436
if (self.major_ticks.get_visible() and not self.major_ticks.get_tick_out()) \
14371437
or \
14381438
(self.minor_ticks.get_visible() and not self.major_ticks.get_tick_out()):
14391439
axislabel_pad = self.major_ticks._ticksize
14401440
else:
14411441
axislabel_pad = 0
14421442
else:
1443-
axislabel_pad = max([self.major_ticklabels._axislabel_pad,
1444-
self.minor_ticklabels._axislabel_pad])
1443+
axislabel_pad = max(self.major_ticklabels._axislabel_pad,
1444+
self.minor_ticklabels._axislabel_pad)
14451445

14461446

14471447
#label_offset = axislabel_pad + self.LABELPAD
@@ -1477,17 +1477,16 @@ def _draw_label2(self, renderer):
14771477

14781478
#print self._ticklabel_add_angle - self._axislabel_add_angle
14791479
#if abs(self._ticklabel_add_angle - self._axislabel_add_angle)%360 > 90:
1480-
if self._ticklabel_add_angle != self._axislabel_add_angle:
1480+
if self._ticklabel_add_angle != self._axislabel_add_angle:
14811481
if (self.major_ticks.get_visible() and not self.major_ticks.get_tick_out()) \
14821482
or \
14831483
(self.minor_ticks.get_visible() and not self.major_ticks.get_tick_out()):
14841484
axislabel_pad = self.major_ticks._ticksize
14851485
else:
14861486
axislabel_pad = 0
14871487
else:
1488-
axislabel_pad = max([self.major_ticklabels._axislabel_pad,
1489-
self.minor_ticklabels._axislabel_pad])
1490-
1488+
axislabel_pad = max(self.major_ticklabels._axislabel_pad,
1489+
self.minor_ticklabels._axislabel_pad)
14911490

14921491
#label_offset = axislabel_pad + self.LABELPAD
14931492

@@ -1497,8 +1496,7 @@ def _draw_label2(self, renderer):
14971496
xy, angle_tangent = self._axis_artist_helper.get_axislabel_pos_angle(self.axes)
14981497
if xy is None: return
14991498

1500-
angle_label = angle_tangent - 90
1501-
1499+
angle_label = angle_tangent - 90
15021500

15031501
x, y = xy
15041502
self.label._set_ref_angle(angle_label+self._axislabel_add_angle)

lib/mpl_toolkits/tests/test_axes_grid1.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def test_divider_append_axes():
4343

4444
# now determine nice limits by hand:
4545
binwidth = 0.25
46-
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))])
46+
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
4747
lim = (int(xymax/binwidth) + 1) * binwidth
4848

4949
bins = np.arange(-lim, lim + binwidth, binwidth)

0 commit comments

Comments
 (0)