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

Skip to content

Stop using np.{builtin}, and fix bugs due to the previous confusion #8996

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 2 commits into from
Aug 6, 2017
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
4 changes: 2 additions & 2 deletions examples/event_handling/viewlims.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __call__(self, xstart, xend, ystart, yend):
self.y = np.linspace(ystart, yend, self.height).reshape(-1, 1)
c = self.x + 1.0j * self.y
threshold_time = np.zeros((self.height, self.width))
z = np.zeros(threshold_time.shape, dtype=np.complex)
mask = np.ones(threshold_time.shape, dtype=np.bool)
z = np.zeros(threshold_time.shape, dtype=complex)
mask = np.ones(threshold_time.shape, dtype=bool)
for i in range(self.niter):
z[mask] = z[mask]**self.power + c[mask]
mask = (np.abs(z) < self.radius)
Expand Down
2 changes: 1 addition & 1 deletion examples/images_contours_and_fields/contour_corner_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
z = np.sin(0.5 * x) * np.cos(0.52 * y)

# Mask various z values.
mask = np.zeros_like(z, dtype=np.bool)
mask = np.zeros_like(z, dtype=bool)
mask[2, 3:5] = True
mask[3:5, 4] = True
mask[7, 2] = True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def experiment_res(x, y):
ntri = tri.triangles.shape[0]

# Some invalid data are masked out
mask_init = np.zeros(ntri, dtype=np.bool)
mask_init = np.zeros(ntri, dtype=bool)
masked_tri = random_gen.randint(0, ntri, int(ntri * init_mask_frac))
mask_init[masked_tri] = True
tri.set_mask(mask_init)
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4769,9 +4769,9 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
y2 = np.ones_like(x) * y2

if where is None:
where = np.ones(len(x), np.bool)
where = np.ones(len(x), bool)
else:
where = np.asarray(where, np.bool)
where = np.asarray(where, bool)

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

if where is None:
where = np.ones(len(y), np.bool)
where = np.ones(len(y), bool)
else:
where = np.asarray(where, np.bool)
where = np.asarray(where, bool)

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

N = len(yslice)
Y = np.zeros((2 * N + 2, 2), np.float)
Y = np.zeros((2 * N + 2, 2), float)
if interpolate:
def get_interp_point(ind):
im1 = max(ind - 1, 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ def hsv_to_rgb(hsv):
g = np.empty_like(h)
b = np.empty_like(h)

i = (h * 6.0).astype(np.int)
i = (h * 6.0).astype(int)
f = (h * 6.0) - i
p = v * (1.0 - s)
q = v * (1.0 - s * f)
Expand Down
28 changes: 14 additions & 14 deletions lib/matplotlib/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,27 @@ def md5(x):
(str('year'), np.int16),
(str('month'), np.int8),
(str('day'), np.int8),
(str('d'), np.float), # mpl datenum
(str('open'), np.float),
(str('high'), np.float),
(str('low'), np.float),
(str('close'), np.float),
(str('volume'), np.float),
(str('aclose'), np.float)])
(str('d'), float), # mpl datenum
(str('open'), float),
(str('high'), float),
(str('low'), float),
(str('close'), float),
(str('volume'), float),
(str('aclose'), float)])


stock_dt_ochl = np.dtype(
[(str('date'), object),
(str('year'), np.int16),
(str('month'), np.int8),
(str('day'), np.int8),
(str('d'), np.float), # mpl datenum
(str('open'), np.float),
(str('close'), np.float),
(str('high'), np.float),
(str('low'), np.float),
(str('volume'), np.float),
(str('aclose'), np.float)])
(str('d'), float), # mpl datenum
(str('open'), float),
(str('close'), float),
(str('high'), float),
(str('low'), float),
(str('volume'), float),
(str('aclose'), float)])


def parse_yahoo_historical_ochl(fh, adjusted=True, asobject=False):
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -3136,17 +3136,17 @@ def get_type(item, atype=int):
def get_justify(colname, column, precision):
ntype = column.dtype

if np.issubdtype(ntype, str) or np.issubdtype(ntype, bytes):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This didn't catch unicode on python 2, but did on python 3

if np.issubdtype(ntype, np.character):
fixed_width = int(ntype.str[2:])
length = max(len(colname), fixed_width)
return 0, length+padding, "%s" # left justify

if np.issubdtype(ntype, np.int):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was false for ntype == np.uint8

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

if np.issubdtype(ntype, np.float):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This worked correctly, but will raise a warning in numpy 1.14 if numpy/numpy#9505 is merged

if np.issubdtype(ntype, np.floating):
fmt = "%." + str(precision) + "f"
length = max(
len(colname),
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -982,12 +982,12 @@ def _find_tails(self, mag, rounding=True, half=5, full=10, flag=50):
# If rounding, round to the nearest multiple of half, the smallest
# increment
if rounding:
mag = half * (mag / half + 0.5).astype(np.int)
mag = half * (mag / half + 0.5).astype(int)

num_flags = np.floor(mag / flag).astype(np.int)
num_flags = np.floor(mag / flag).astype(int)
mag = np.mod(mag, flag)

num_barb = np.floor(mag / full).astype(np.int)
num_barb = np.floor(mag / full).astype(int)
mag = np.mod(mag, full)

half_flag = mag >= half
Expand Down
8 changes: 4 additions & 4 deletions lib/matplotlib/streamplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,14 +599,14 @@ def interpgrid(a, xi, yi):

Ny, Nx = np.shape(a)
if isinstance(xi, np.ndarray):
x = xi.astype(np.int)
y = yi.astype(np.int)
x = xi.astype(int)
y = yi.astype(int)
# Check that xn, yn don't exceed max index
xn = np.clip(x + 1, 0, Nx - 1)
yn = np.clip(y + 1, 0, Ny - 1)
else:
x = np.int(xi)
y = np.int(yi)
x = int(xi)
y = int(yi)
# conditional is faster than clipping for integers
if x == (Nx - 2):
xn = x
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def test_mask_image():

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

A = np.zeros((5, 5), dtype=np.bool)
A = np.zeros((5, 5), dtype=bool)
A[1:2, 1:2] = True
A = np.ma.masked_array(np.ones((5, 5), dtype=np.uint16), A)

Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/tests/test_triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ def test_tritools():
x = np.array([0., 1., 0.5, 0., 2.])
y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
mask = np.array([False, False, True], dtype=np.bool)
mask = np.array([False, False, True], dtype=bool)
triang = mtri.Triangulation(x, y, triangles, mask=mask)
analyser = mtri.TriAnalyzer(triang)
assert_array_almost_equal(analyser.scale_factors,
Expand Down Expand Up @@ -881,15 +881,15 @@ def power(x, a):
triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1))
analyser = mtri.TriAnalyzer(triang)
mask_flat = analyser.get_flat_tri_mask(0.2)
verif_mask = np.zeros(162, dtype=np.bool)
verif_mask = np.zeros(162, dtype=bool)
corners_index = [0, 1, 2, 3, 14, 15, 16, 17, 18, 19, 34, 35, 126, 127,
142, 143, 144, 145, 146, 147, 158, 159, 160, 161]
verif_mask[corners_index] = True
assert_array_equal(mask_flat, verif_mask)

# Now including a hole (masked triangle) at the center. The center also
# shall be eliminated by get_flat_tri_mask.
mask = np.zeros(162, dtype=np.bool)
mask = np.zeros(162, dtype=bool)
mask[80] = True
triang.set_mask(mask)
mask_flat = analyser.get_flat_tri_mask(0.2)
Expand All @@ -906,7 +906,7 @@ def test_trirefine():
x, y = np.meshgrid(x, x)
x = x.ravel()
y = y.ravel()
mask = np.zeros(2*n**2, dtype=np.bool)
mask = np.zeros(2*n**2, dtype=bool)
mask[n**2:] = True
triang = mtri.Triangulation(x, y, triangles=meshgrid_triangles(n+1),
mask=mask)
Expand Down Expand Up @@ -1032,7 +1032,7 @@ def test_trianalyzer_mismatched_indices():
x = np.array([0., 1., 0.5, 0., 2.])
y = np.array([0., 0., 0.5*np.sqrt(3.), -1., 1.])
triangles = np.array([[0, 1, 2], [0, 1, 3], [1, 2, 4]], dtype=np.int32)
mask = np.array([False, False, True], dtype=np.bool)
mask = np.array([False, False, True], dtype=bool)
triang = mtri.Triangulation(x, y, triangles, mask=mask)
analyser = mtri.TriAnalyzer(triang)
# numpy >= 1.10 raises a VisibleDeprecationWarning in the following line
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tri/triangulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def __init__(self, x, y, triangles=None, mask=None):
raise ValueError('triangles min element is out of bounds')

if mask is not None:
self.mask = np.asarray(mask, dtype=np.bool)
self.mask = np.asarray(mask, dtype=bool)
if self.mask.shape != (self.triangles.shape[0],):
raise ValueError('mask array must have same length as '
'triangles array')
Expand Down Expand Up @@ -200,7 +200,7 @@ def set_mask(self, mask):
if mask is None:
self.mask = None
else:
self.mask = np.asarray(mask, dtype=np.bool)
self.mask = np.asarray(mask, dtype=bool)
if self.mask.shape != (self.triangles.shape[0],):
raise ValueError('mask array must have same length as '
'triangles array')
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/tritools.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def get_flat_tri_mask(self, min_circle_ratio=0.01, rescale=True):

current_mask = self._triangulation.mask
if current_mask is None:
current_mask = np.zeros(ntri, dtype=np.bool)
current_mask = np.zeros(ntri, dtype=bool)
valid_neighbors = np.copy(self._triangulation.neighbors)
renum_neighbors = np.arange(ntri, dtype=np.int32)
nadd = -1
Expand Down
4 changes: 2 additions & 2 deletions lib/mpl_toolkits/tests/test_mplot3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ def test_poly3dcollection_closed():
fig = plt.figure()
ax = fig.gca(projection='3d')

poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], np.float)
poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], np.float)
poly1 = np.array([[0, 0, 1], [0, 1, 1], [0, 0, 0]], float)
poly2 = np.array([[0, 1, 1], [1, 1, 1], [1, 1, 0]], float)
c1 = art3d.Poly3DCollection([poly1], linewidths=3, edgecolor='k',
facecolor=(0.5, 0.5, 1, 0.5), closed=True)
c2 = art3d.Poly3DCollection([poly2], linewidths=3, edgecolor='k',
Expand Down