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

Skip to content

Commit f077d49

Browse files
authored
Merge pull request #8996 from eric-wieser/outdated-sctype-use
MNT: Stop using np.{builtin}, and fix bugs due to the previous confusion
2 parents a1937d4 + 7b8883c commit f077d49

File tree

14 files changed

+45
-45
lines changed

14 files changed

+45
-45
lines changed

examples/event_handling/viewlims.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def __call__(self, xstart, xend, ystart, yend):
3636
self.y = np.linspace(ystart, yend, self.height).reshape(-1, 1)
3737
c = self.x + 1.0j * self.y
3838
threshold_time = np.zeros((self.height, self.width))
39-
z = np.zeros(threshold_time.shape, dtype=np.complex)
40-
mask = np.ones(threshold_time.shape, dtype=np.bool)
39+
z = np.zeros(threshold_time.shape, dtype=complex)
40+
mask = np.ones(threshold_time.shape, dtype=bool)
4141
for i in range(self.niter):
4242
z[mask] = z[mask]**self.power + c[mask]
4343
mask = (np.abs(z) < self.radius)

examples/images_contours_and_fields/contour_corner_mask.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
z = np.sin(0.5 * x) * np.cos(0.52 * y)
1515

1616
# Mask various z values.
17-
mask = np.zeros_like(z, dtype=np.bool)
17+
mask = np.zeros_like(z, dtype=bool)
1818
mask[2, 3:5] = True
1919
mask[3:5, 4] = True
2020
mask[7, 2] = True

examples/images_contours_and_fields/tricontour_smooth_delaunay.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def experiment_res(x, y):
7575
ntri = tri.triangles.shape[0]
7676

7777
# Some invalid data are masked out
78-
mask_init = np.zeros(ntri, dtype=np.bool)
78+
mask_init = np.zeros(ntri, dtype=bool)
7979
masked_tri = random_gen.randint(0, ntri, int(ntri * init_mask_frac))
8080
mask_init[masked_tri] = True
8181
tri.set_mask(mask_init)

lib/matplotlib/axes/_axes.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4769,9 +4769,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
47694769
y2 = np.ones_like(x) * y2
47704770

47714771
if where is None:
4772-
where = np.ones(len(x), np.bool)
4772+
where = np.ones(len(x), bool)
47734773
else:
4774-
where = np.asarray(where, np.bool)
4774+
where = np.asarray(where, bool)
47754775

47764776
if not (x.shape == y1.shape == y2.shape == where.shape):
47774777
raise ValueError("Argument dimensions are incompatible")
@@ -4930,9 +4930,9 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49304930
x2 = np.ones_like(y) * x2
49314931

49324932
if where is None:
4933-
where = np.ones(len(y), np.bool)
4933+
where = np.ones(len(y), bool)
49344934
else:
4935-
where = np.asarray(where, np.bool)
4935+
where = np.asarray(where, bool)
49364936

49374937
if not (y.shape == x1.shape == x2.shape == where.shape):
49384938
raise ValueError("Argument dimensions are incompatible")
@@ -4954,7 +4954,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
49544954
continue
49554955

49564956
N = len(yslice)
4957-
Y = np.zeros((2 * N + 2, 2), np.float)
4957+
Y = np.zeros((2 * N + 2, 2), float)
49584958
if interpolate:
49594959
def get_interp_point(ind):
49604960
im1 = max(ind - 1, 0)

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ def hsv_to_rgb(hsv):
14431443
g = np.empty_like(h)
14441444
b = np.empty_like(h)
14451445

1446-
i = (h * 6.0).astype(np.int)
1446+
i = (h * 6.0).astype(int)
14471447
f = (h * 6.0) - i
14481448
p = v * (1.0 - s)
14491449
q = v * (1.0 - s * f)

lib/matplotlib/finance.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,27 @@ def md5(x):
5858
(str('year'), np.int16),
5959
(str('month'), np.int8),
6060
(str('day'), np.int8),
61-
(str('d'), np.float), # mpl datenum
62-
(str('open'), np.float),
63-
(str('high'), np.float),
64-
(str('low'), np.float),
65-
(str('close'), np.float),
66-
(str('volume'), np.float),
67-
(str('aclose'), np.float)])
61+
(str('d'), float), # mpl datenum
62+
(str('open'), float),
63+
(str('high'), float),
64+
(str('low'), float),
65+
(str('close'), float),
66+
(str('volume'), float),
67+
(str('aclose'), float)])
6868

6969

7070
stock_dt_ochl = np.dtype(
7171
[(str('date'), object),
7272
(str('year'), np.int16),
7373
(str('month'), np.int8),
7474
(str('day'), np.int8),
75-
(str('d'), np.float), # mpl datenum
76-
(str('open'), np.float),
77-
(str('close'), np.float),
78-
(str('high'), np.float),
79-
(str('low'), np.float),
80-
(str('volume'), np.float),
81-
(str('aclose'), np.float)])
75+
(str('d'), float), # mpl datenum
76+
(str('open'), float),
77+
(str('close'), float),
78+
(str('high'), float),
79+
(str('low'), float),
80+
(str('volume'), float),
81+
(str('aclose'), float)])
8282

8383

8484
def parse_yahoo_historical_ochl(fh, adjusted=True, asobject=False):

lib/matplotlib/mlab.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3136,17 +3136,17 @@ def get_type(item, atype=int):
31363136
def get_justify(colname, column, precision):
31373137
ntype = column.dtype
31383138

3139-
if np.issubdtype(ntype, str) or np.issubdtype(ntype, bytes):
3139+
if np.issubdtype(ntype, np.character):
31403140
fixed_width = int(ntype.str[2:])
31413141
length = max(len(colname), fixed_width)
31423142
return 0, length+padding, "%s" # left justify
31433143

3144-
if np.issubdtype(ntype, np.int):
3144+
if np.issubdtype(ntype, np.integer):
31453145
length = max(len(colname),
31463146
np.max(list(map(len, list(map(str, column))))))
31473147
return 1, length+padding, "%d" # right justify
31483148

3149-
if np.issubdtype(ntype, np.float):
3149+
if np.issubdtype(ntype, np.floating):
31503150
fmt = "%." + str(precision) + "f"
31513151
length = max(
31523152
len(colname),

lib/matplotlib/quiver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,12 +982,12 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
982982
# If rounding, round to the nearest multiple of half, the smallest
983983
# increment
984984
if rounding:
985-
mag = half * (mag / half + 0.5).astype(np.int)
985+
mag = half * (mag / half + 0.5).astype(int)
986986

987-
num_flags = np.floor(mag / flag).astype(np.int)
987+
num_flags = np.floor(mag / flag).astype(int)
988988
mag = np.mod(mag, flag)
989989

990-
num_barb = np.floor(mag / full).astype(np.int)
990+
num_barb = np.floor(mag / full).astype(int)
991991
mag = np.mod(mag, full)
992992

993993
half_flag = mag >= half

lib/matplotlib/streamplot.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -599,14 +599,14 @@ def interpgrid(a, xi, yi):
599599

600600
Ny, Nx = np.shape(a)
601601
if isinstance(xi, np.ndarray):
602-
x = xi.astype(np.int)
603-
y = yi.astype(np.int)
602+
x = xi.astype(int)
603+
y = yi.astype(int)
604604
# Check that xn, yn don't exceed max index
605605
xn = np.clip(x + 1, 0, Nx - 1)
606606
yn = np.clip(y + 1, 0, Ny - 1)
607607
else:
608-
x = np.int(xi)
609-
y = np.int(yi)
608+
x = int(xi)
609+
y = int(yi)
610610
# conditional is faster than clipping for integers
611611
if x == (Nx - 2):
612612
xn = x

lib/matplotlib/tests/test_image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ def test_mask_image():
705705

706706
ax1.imshow(A, interpolation='nearest')
707707

708-
A = np.zeros((5, 5), dtype=np.bool)
708+
A = np.zeros((5, 5), dtype=bool)
709709
A[1:2, 1:2] = True
710710
A = np.ma.masked_array(np.ones((5, 5), dtype=np.uint16), A)
711711

lib/matplotlib/tests/test_triangulation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ def test_tritools():
847847
x = np.array([0., 1., 0.5, 0., 2.])
848848
y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
849849
triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
850-
mask = np.array([False, False, True], dtype=np.bool)
850+
mask = np.array([False, False, True], dtype=bool)
851851
triang = mtri.Triangulation(x, y, triangles, mask=mask)
852852
analyser = mtri.TriAnalyzer(triang)
853853
assert_array_almost_equal(analyser.scale_factors,
@@ -881,15 +881,15 @@ def power(x, a):
881881
triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1))
882882
analyser = mtri.TriAnalyzer(triang)
883883
mask_flat = analyser.get_flat_tri_mask(0.2)
884-
verif_mask = np.zeros(162, dtype=np.bool)
884+
verif_mask = np.zeros(162, dtype=bool)
885885
corners_index = [0, 1, 2, 3, 14, 15, 16, 17, 18, 19, 34, 35, 126, 127,
886886
142, 143, 144, 145, 146, 147, 158, 159, 160, 161]
887887
verif_mask[corners_index] = True
888888
assert_array_equal(mask_flat, verif_mask)
889889

890890
# Now including a hole (masked triangle) at the center. The center also
891891
# shall be eliminated by get_flat_tri_mask.
892-
mask = np.zeros(162, dtype=np.bool)
892+
mask = np.zeros(162, dtype=bool)
893893
mask[80] = True
894894
triang.set_mask(mask)
895895
mask_flat = analyser.get_flat_tri_mask(0.2)
@@ -906,7 +906,7 @@ def test_trirefine():
906906
x, y = np.meshgrid(x, x)
907907
x = x.ravel()
908908
y = y.ravel()
909-
mask = np.zeros(2*n**2, dtype=np.bool)
909+
mask = np.zeros(2*n**2, dtype=bool)
910910
mask[n**2:] = True
911911
triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1),
912912
mask=mask)
@@ -1032,7 +1032,7 @@ def test_trianalyzer_mismatched_indices():
10321032
x = np.array([0., 1., 0.5, 0., 2.])
10331033
y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
10341034
triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
1035-
mask = np.array([False, False, True], dtype=np.bool)
1035+
mask = np.array([False, False, True], dtype=bool)
10361036
triang = mtri.Triangulation(x, y, triangles, mask=mask)
10371037
analyser = mtri.TriAnalyzer(triang)
10381038
# numpy >= 1.10 raises a VisibleDeprecationWarning in the following line

lib/matplotlib/tri/triangulation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, x, y, triangles=None, mask=None):
6666
raise ValueError('triangles min element is out of bounds')
6767

6868
if mask is not None:
69-
self.mask = np.asarray(mask, dtype=np.bool)
69+
self.mask = np.asarray(mask, dtype=bool)
7070
if self.mask.shape != (self.triangles.shape[0],):
7171
raise ValueError('mask array must have same length as '
7272
'triangles array')
@@ -200,7 +200,7 @@ def set_mask(self, mask):
200200
if mask is None:
201201
self.mask = None
202202
else:
203-
self.mask = np.asarray(mask, dtype=np.bool)
203+
self.mask = np.asarray(mask, dtype=bool)
204204
if self.mask.shape != (self.triangles.shape[0],):
205205
raise ValueError('mask array must have same length as '
206206
'triangles array')

lib/matplotlib/tri/tritools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def get_flat_tri_mask(self, min_circle_ratio=0.01, rescale=True):
177177

178178
current_mask = self._triangulation.mask
179179
if current_mask is None:
180-
current_mask = np.zeros(ntri, dtype=np.bool)
180+
current_mask = np.zeros(ntri, dtype=bool)
181181
valid_neighbors = np.copy(self._triangulation.neighbors)
182182
renum_neighbors = np.arange(ntri, dtype=np.int32)
183183
nadd = -1

lib/mpl_toolkits/tests/test_mplot3d.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,8 +343,8 @@ def test_poly3dcollection_closed():
343343
fig = plt.figure()
344344
ax = fig.gca(projection='3d')
345345

346-
poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], np.float)
347-
poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], np.float)
346+
poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float)
347+
poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], float)
348348
c1 = art3d.Poly3DCollection([poly1], linewidths=3, edgecolor='k',
349349
facecolor=(0.5, 0.5, 1, 0.5), closed=True)
350350
c2 = art3d.Poly3DCollection([poly2], linewidths=3, edgecolor='k',

0 commit comments

Comments
 (0)