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

Skip to content

Commit 9a42b8d

Browse files
committed
Merge pull request #3241 from jenshnielsen/numpy_clean_warnings
Cast to integer to get rid of numpy warning
2 parents 82ac087 + a7e673d commit 9a42b8d

File tree

9 files changed

+22
-21
lines changed

9 files changed

+22
-21
lines changed

lib/matplotlib/bezier.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):
256256

257257
for ctl_points, command in path_iter:
258258
iold = i
259-
i += len(ctl_points) / 2
259+
i += len(ctl_points) // 2
260260
if inside(ctl_points[-2:]) != begin_inside:
261261
bezier_path = concat([ctl_points_old[-2:], ctl_points])
262262
break

lib/matplotlib/cbook.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ def simple_linear_interpolation(a, steps):
17371737
if steps == 1:
17381738
return a
17391739

1740-
steps = np.floor(steps)
1740+
steps = int(np.floor(steps))
17411741
new_length = ((len(a) - 1) * steps) + 1
17421742
new_shape = list(a.shape)
17431743
new_shape[0] = new_length
@@ -1747,7 +1747,6 @@ def simple_linear_interpolation(a, steps):
17471747
a0 = a[0:-1]
17481748
a1 = a[1:]
17491749
delta = ((a1 - a0) / steps)
1750-
steps = int(steps)
17511750
for i in range(1, steps):
17521751
result[i::steps] = delta * i + a0
17531752
result[steps::steps] = a1

lib/matplotlib/colors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,8 @@ def is_color_like(c):
222222

223223
def rgb2hex(rgb):
224224
'Given an rgb or rgba sequence of 0-1 floats, return the hex string'
225-
return '#%02x%02x%02x' % tuple([np.round(val * 255) for val in rgb[:3]])
225+
a = '#%02x%02x%02x' % tuple([int(np.round(val * 255)) for val in rgb[:3]])
226+
return a
226227

227228
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
228229

lib/matplotlib/contour.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -474,20 +474,21 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
474474
xy2 = mlab.less_simple_linear_interpolation(
475475
pl, lc, [xi[1]])
476476

477-
# Make integer
477+
# Round to integer values but keep as float
478+
# To allow check against nan below
478479
I = [np.floor(I[0]), np.ceil(I[1])]
479480

480481
# Actually break contours
481482
if closed:
482483
# This will remove contour if shorter than label
483484
if np.all(~np.isnan(I)):
484-
nlc.append(np.r_[xy2, lc[I[1]:I[0] + 1], xy1])
485+
nlc.append(np.r_[xy2, lc[int(I[1]):int(I[0]) + 1], xy1])
485486
else:
486487
# These will remove pieces of contour if they have length zero
487488
if not np.isnan(I[0]):
488-
nlc.append(np.r_[lc[:I[0] + 1], xy1])
489+
nlc.append(np.r_[lc[:int(I[0]) + 1], xy1])
489490
if not np.isnan(I[1]):
490-
nlc.append(np.r_[xy2, lc[I[1]:]])
491+
nlc.append(np.r_[xy2, lc[int(I[1]):]])
491492

492493
# The current implementation removes contours completely
493494
# covered by labels. Uncomment line below to keep

lib/matplotlib/hatch.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class HatchPatternBase:
2121

2222
class HorizontalHatch(HatchPatternBase):
2323
def __init__(self, hatch, density):
24-
self.num_lines = (hatch.count('-') + hatch.count('+')) * density
24+
self.num_lines = int((hatch.count('-') + hatch.count('+')) * density)
2525
self.num_vertices = self.num_lines * 2
2626

2727
def set_vertices_and_codes(self, vertices, codes):
@@ -38,7 +38,7 @@ def set_vertices_and_codes(self, vertices, codes):
3838

3939
class VerticalHatch(HatchPatternBase):
4040
def __init__(self, hatch, density):
41-
self.num_lines = (hatch.count('|') + hatch.count('+')) * density
41+
self.num_lines = int((hatch.count('|') + hatch.count('+')) * density)
4242
self.num_vertices = self.num_lines * 2
4343

4444
def set_vertices_and_codes(self, vertices, codes):
@@ -55,8 +55,8 @@ def set_vertices_and_codes(self, vertices, codes):
5555

5656
class NorthEastHatch(HatchPatternBase):
5757
def __init__(self, hatch, density):
58-
self.num_lines = (hatch.count('/') + hatch.count('x') +
59-
hatch.count('X')) * density
58+
self.num_lines = int((hatch.count('/') + hatch.count('x') +
59+
hatch.count('X')) * density)
6060
if self.num_lines:
6161
self.num_vertices = (self.num_lines + 1) * 2
6262
else:
@@ -74,8 +74,8 @@ def set_vertices_and_codes(self, vertices, codes):
7474

7575
class SouthEastHatch(HatchPatternBase):
7676
def __init__(self, hatch, density):
77-
self.num_lines = (hatch.count('\\') + hatch.count('x') +
78-
hatch.count('X')) * density
77+
self.num_lines = int((hatch.count('\\') + hatch.count('x') +
78+
hatch.count('X')) * density)
7979
self.num_vertices = (self.num_lines + 1) * 2
8080
if self.num_lines:
8181
self.num_vertices = (self.num_lines + 1) * 2
@@ -100,8 +100,8 @@ def __init__(self, hatch, density):
100100
self.num_shapes = 0
101101
self.num_vertices = 0
102102
else:
103-
self.num_shapes = ((self.num_rows / 2 + 1) * (self.num_rows + 1) +
104-
(self.num_rows / 2) * (self.num_rows))
103+
self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) +
104+
(self.num_rows // 2) * (self.num_rows))
105105
self.num_vertices = (self.num_shapes *
106106
len(self.shape_vertices) *
107107
(self.filled and 1 or 2))

lib/matplotlib/tests/test_axes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def test_nonfinite_limits():
523523
y = np.log(x)
524524
finally:
525525
np.seterr(**olderr)
526-
x[len(x)/2] = np.nan
526+
x[len(x)//2] = np.nan
527527
fig = plt.figure()
528528
ax = fig.add_subplot(111)
529529
ax.plot(x, y)

lib/matplotlib/tests/test_mlab.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,8 +1326,8 @@ def createStim(self, fstims, iscomplex, sides, nsides, len_x=None,
13261326

13271327
freqs_specgram = freqs_density
13281328
# time points for specgram
1329-
t_start = NFFT_specgram_real/2
1330-
t_stop = len(x) - NFFT_specgram_real/2+1
1329+
t_start = NFFT_specgram_real//2
1330+
t_stop = len(x) - NFFT_specgram_real//2+1
13311331
t_step = NFFT_specgram_real - nover_specgram_real
13321332
t_specgram = x[t_start:t_stop:t_step]
13331333
if NFFT_specgram_real % 2:

lib/matplotlib/tests/test_simplification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def test_start_with_moveto():
153153
decodebytes = base64.decodestring
154154

155155
verts = np.fromstring(decodebytes(data), dtype='<i4')
156-
verts = verts.reshape((len(verts) / 2, 2))
156+
verts = verts.reshape((len(verts) // 2, 2))
157157
path = Path(verts)
158158
segs = path.iter_segments(transforms.IdentityTransform(), clip=(0.0, 0.0, 100.0, 100.0))
159159
segs = list(segs)

lib/matplotlib/tri/trirefine.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def _refine_triangulation_once(triangulation, ancestors=None):
231231
# points
232232
# hint: each apex is shared by 2 masked_triangles except the borders.
233233
borders = np.sum(neighbors == -1)
234-
added_pts = (3*ntri + borders) / 2
234+
added_pts = (3*ntri + borders) // 2
235235
refi_npts = npts + added_pts
236236
refi_x = np.zeros(refi_npts)
237237
refi_y = np.zeros(refi_npts)

0 commit comments

Comments
 (0)