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

Skip to content

Commit 099c168

Browse files
authored
Merge pull request #15853 from anntzer/absless
np.abs -> (builtins).abs
2 parents 4d48beb + d8766f8 commit 099c168

File tree

8 files changed

+18
-23
lines changed

8 files changed

+18
-23
lines changed

examples/event_handling/resample.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@ def downsample(self, xstart, xend):
3737
xdata = xdata[::ratio]
3838
ydata = ydata[::ratio]
3939

40-
print("using {} of {} visible points".format(
41-
len(ydata), np.sum(mask)))
40+
print("using {} of {} visible points".format(len(ydata), np.sum(mask)))
4241

4342
return xdata, ydata
4443

4544
def update(self, ax):
4645
# Update the line
4746
lims = ax.viewLim
48-
if np.abs(lims.width - self.delta) > 1e-8:
47+
if abs(lims.width - self.delta) > 1e-8:
4948
self.delta = lims.width
5049
xstart, xend = lims.intervalx
5150
self.line.set_data(*self.downsample(xstart, xend))

examples/specialty_plots/hinton_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def hinton(matrix, max_weight=None, ax=None):
1919
ax = ax if ax is not None else plt.gca()
2020

2121
if not max_weight:
22-
max_weight = 2 ** np.ceil(np.log(np.abs(matrix).max()) / np.log(2))
22+
max_weight = 2 ** np.ceil(np.log2(np.abs(matrix).max()))
2323

2424
ax.patch.set_facecolor('gray')
2525
ax.set_aspect('equal', 'box')
@@ -28,7 +28,7 @@ def hinton(matrix, max_weight=None, ax=None):
2828

2929
for (x, y), w in np.ndenumerate(matrix):
3030
color = 'white' if w > 0 else 'black'
31-
size = np.sqrt(np.abs(w) / max_weight)
31+
size = np.sqrt(abs(w) / max_weight)
3232
rect = plt.Rectangle([x - size / 2, y - size / 2], size, size,
3333
facecolor=color, edgecolor=color)
3434
ax.add_patch(rect)

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6276,8 +6276,8 @@ def pcolorfast(self, *args, alpha=None, norm=None, cmap=None, vmin=None,
62766276
else:
62776277
dx = np.diff(x)
62786278
dy = np.diff(y)
6279-
if (np.ptp(dx) < 0.01 * np.abs(dx.mean()) and
6280-
np.ptp(dy) < 0.01 * np.abs(dy.mean())):
6279+
if (np.ptp(dx) < 0.01 * abs(dx.mean()) and
6280+
np.ptp(dy) < 0.01 * abs(dy.mean())):
62816281
style = "image"
62826282
else:
62836283
style = "pcolorimage"

lib/matplotlib/bezier.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def get_intersection(cx1, cy1, cos_t1, sin_t1,
3434
c, d = sin_t2, -cos_t2
3535

3636
ad_bc = a * d - b * c
37-
if np.abs(ad_bc) < 1.0e-12:
37+
if abs(ad_bc) < 1e-12:
3838
raise ValueError("Given lines do not intersect. Please verify that "
3939
"the angles are not equal or differ by 180 degrees.")
4040

@@ -368,10 +368,10 @@ def check_if_parallel(dx1, dy1, dx2, dy2, tolerance=1.e-5):
368368
"""
369369
theta1 = np.arctan2(dx1, dy1)
370370
theta2 = np.arctan2(dx2, dy2)
371-
dtheta = np.abs(theta1 - theta2)
371+
dtheta = abs(theta1 - theta2)
372372
if dtheta < tolerance:
373373
return 1
374-
elif np.abs(dtheta - np.pi) < tolerance:
374+
elif abs(dtheta - np.pi) < tolerance:
375375
return -1
376376
else:
377377
return False

lib/matplotlib/markers.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -330,19 +330,15 @@ def _set_nothing(self):
330330
self._filled = False
331331

332332
def _set_custom_marker(self, path):
333-
verts = path.vertices
334-
rescale = max(np.max(np.abs(verts[:, 0])),
335-
np.max(np.abs(verts[:, 1])))
333+
rescale = np.max(np.abs(path.vertices)) # max of x's and y's.
336334
self._transform = Affine2D().scale(0.5 / rescale)
337335
self._path = path
338336

339337
def _set_path_marker(self):
340338
self._set_custom_marker(self._marker)
341339

342340
def _set_vertices(self):
343-
verts = self._marker
344-
marker = Path(verts)
345-
self._set_custom_marker(marker)
341+
self._set_custom_marker(Path(self._marker))
346342

347343
def _set_tuple_marker(self):
348344
marker = self._marker

lib/matplotlib/sankey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ def add(self, patchlabel='', flows=None, orientations=None, labels='',
463463
raise ValueError(
464464
"'trunklength' is negative, which is not allowed because it "
465465
"would cause poor layout")
466-
if np.abs(np.sum(flows)) > self.tolerance:
466+
if abs(np.sum(flows)) > self.tolerance:
467467
_log.info("The sum of the flows is nonzero (%f; patchlabel=%r); "
468468
"is the system not at steady state?",
469469
np.sum(flows), patchlabel)

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,7 @@ def test_format_data_short(self, N):
10081008
x2 = 1 - float(fx[2:])
10091009
else:
10101010
x2 = float(fx)
1011-
assert np.abs(x - x2) < 1 / N
1011+
assert abs(x - x2) < 1 / N
10121012

10131013

10141014
class TestFormatStrFormatter:

lib/matplotlib/ticker.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ def __call__(self, x, pos=None):
575575
return ''
576576
else:
577577
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
578-
if np.abs(xp) < 1e-8:
578+
if abs(xp) < 1e-8:
579579
xp = 0
580580
if self._useLocale:
581581
s = locale.format_string(self.format, (xp,))
@@ -792,7 +792,7 @@ def _set_format(self):
792792
@cbook.deprecated("3.1")
793793
def pprint_val(self, x):
794794
xp = (x - self.offset) / (10. ** self.orderOfMagnitude)
795-
if np.abs(xp) < 1e-8:
795+
if abs(xp) < 1e-8:
796796
xp = 0
797797
if self._useLocale:
798798
return locale.format_string(self.format, (xp,))
@@ -1123,7 +1123,7 @@ def __call__(self, x, pos=None):
11231123
else:
11241124
base = '%s' % b
11251125

1126-
if np.abs(fx) < min_exp:
1126+
if abs(fx) < min_exp:
11271127
if usetex:
11281128
return r'${0}{1:g}$'.format(sign_string, x)
11291129
else:
@@ -2269,7 +2269,7 @@ def is_decade(x, base=10, *, rtol=1e-10):
22692269
return False
22702270
if x == 0.0:
22712271
return True
2272-
lx = np.log(np.abs(x)) / np.log(base)
2272+
lx = np.log(abs(x)) / np.log(base)
22732273
return is_close_to_int(lx, atol=rtol)
22742274

22752275

@@ -2614,7 +2614,7 @@ def get_log_range(lo, hi):
26142614
a_lo, a_hi = (0, 0)
26152615
if has_a:
26162616
a_upper_lim = min(-linthresh, vmax)
2617-
a_lo, a_hi = get_log_range(np.abs(a_upper_lim), np.abs(vmin) + 1)
2617+
a_lo, a_hi = get_log_range(abs(a_upper_lim), abs(vmin) + 1)
26182618

26192619
c_lo, c_hi = (0, 0)
26202620
if has_c:

0 commit comments

Comments
 (0)