Skip to content

Cast to integer to get rid of numpy warning #3241

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 11 commits into from
Aug 26, 2014
2 changes: 1 addition & 1 deletion lib/matplotlib/bezier.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def split_path_inout(path, inside, tolerence=0.01, reorder_inout=False):

for ctl_points, command in path_iter:
iold = i
i += len(ctl_points) / 2
i += len(ctl_points) // 2
if inside(ctl_points[-2:]) != begin_inside:
bezier_path = concat([ctl_points_old[-2:], ctl_points])
break
Expand Down
3 changes: 1 addition & 2 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -1737,7 +1737,7 @@ def simple_linear_interpolation(a, steps):
if steps == 1:
return a

steps = np.floor(steps)
steps = int(np.floor(steps))
new_length = ((len(a) - 1) * steps) + 1
new_shape = list(a.shape)
new_shape[0] = new_length
Expand All @@ -1747,7 +1747,6 @@ def simple_linear_interpolation(a, steps):
a0 = a[0:-1]
a1 = a[1:]
delta = ((a1 - a0) / steps)
steps = int(steps)
for i in range(1, steps):
result[i::steps] = delta * i + a0
result[steps::steps] = a1
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def is_color_like(c):

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

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

Expand Down
9 changes: 5 additions & 4 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -474,20 +474,21 @@ def calc_label_rot_and_inline(self, slc, ind, lw, lc=None, spacing=5):
xy2 = mlab.less_simple_linear_interpolation(
pl, lc, [xi[1]])

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

# Actually break contours
if closed:
# This will remove contour if shorter than label
if np.all(~np.isnan(I)):
nlc.append(np.r_[xy2, lc[I[1]:I[0] + 1], xy1])
nlc.append(np.r_[xy2, lc[int(I[1]):int(I[0]) + 1], xy1])
else:
# These will remove pieces of contour if they have length zero
if not np.isnan(I[0]):
nlc.append(np.r_[lc[:I[0] + 1], xy1])
nlc.append(np.r_[lc[:int(I[0]) + 1], xy1])
if not np.isnan(I[1]):
nlc.append(np.r_[xy2, lc[I[1]:]])
nlc.append(np.r_[xy2, lc[int(I[1]):]])

# The current implementation removes contours completely
# covered by labels. Uncomment line below to keep
Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/hatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class HatchPatternBase:

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

def set_vertices_and_codes(self, vertices, codes):
Expand All @@ -38,7 +38,7 @@ def set_vertices_and_codes(self, vertices, codes):

class VerticalHatch(HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines = (hatch.count('|') + hatch.count('+')) * density
self.num_lines = int((hatch.count('|') + hatch.count('+')) * density)
self.num_vertices = self.num_lines * 2

def set_vertices_and_codes(self, vertices, codes):
Expand All @@ -55,8 +55,8 @@ def set_vertices_and_codes(self, vertices, codes):

class NorthEastHatch(HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines = (hatch.count('/') + hatch.count('x') +
hatch.count('X')) * density
self.num_lines = int((hatch.count('/') + hatch.count('x') +
hatch.count('X')) * density)
if self.num_lines:
self.num_vertices = (self.num_lines + 1) * 2
else:
Expand All @@ -74,8 +74,8 @@ def set_vertices_and_codes(self, vertices, codes):

class SouthEastHatch(HatchPatternBase):
def __init__(self, hatch, density):
self.num_lines = (hatch.count('\\') + hatch.count('x') +
hatch.count('X')) * density
self.num_lines = int((hatch.count('\\') + hatch.count('x') +
hatch.count('X')) * density)
self.num_vertices = (self.num_lines + 1) * 2
if self.num_lines:
self.num_vertices = (self.num_lines + 1) * 2
Expand All @@ -100,8 +100,8 @@ def __init__(self, hatch, density):
self.num_shapes = 0
self.num_vertices = 0
else:
self.num_shapes = ((self.num_rows / 2 + 1) * (self.num_rows + 1) +
(self.num_rows / 2) * (self.num_rows))
self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) +
(self.num_rows // 2) * (self.num_rows))
self.num_vertices = (self.num_shapes *
len(self.shape_vertices) *
(self.filled and 1 or 2))
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def test_nonfinite_limits():
y = np.log(x)
finally:
np.seterr(**olderr)
x[len(x)/2] = np.nan
x[len(x)//2] = np.nan
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -1325,8 +1325,8 @@ def createStim(self, fstims, iscomplex, sides, nsides, len_x=None,

freqs_specgram = freqs_density
# time points for specgram
t_start = NFFT_specgram_real/2
t_stop = len(x) - NFFT_specgram_real/2+1
t_start = NFFT_specgram_real//2
t_stop = len(x) - NFFT_specgram_real//2+1
t_step = NFFT_specgram_real - nover_specgram_real
t_specgram = x[t_start:t_stop:t_step]
if NFFT_specgram_real % 2:
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_simplification.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def test_start_with_moveto():
decodebytes = base64.decodestring

verts = np.fromstring(decodebytes(data), dtype='<i4')
verts = verts.reshape((len(verts) / 2, 2))
verts = verts.reshape((len(verts) // 2, 2))
path = Path(verts)
segs = path.iter_segments(transforms.IdentityTransform(), clip=(0.0, 0.0, 100.0, 100.0))
segs = list(segs)
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tri/trirefine.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def _refine_triangulation_once(triangulation, ancestors=None):
# points
# hint: each apex is shared by 2 masked_triangles except the borders.
borders = np.sum(neighbors == -1)
added_pts = (3*ntri + borders) / 2
added_pts = (3*ntri + borders) // 2
refi_npts = npts + added_pts
refi_x = np.zeros(refi_npts)
refi_y = np.zeros(refi_npts)
Expand Down