Skip to content

Commit 66daba6

Browse files
committed
MNT: Replace use of builtin round() with numpy's.
The behavior of the builtin round() function changed between python 2 and 3. Use numpy's, which matches python 3's, so that we have consistent rounding behavior between python versions. This helps keep image test results (here or downstream) consistent between python versions.
1 parent 3d74ff4 commit 66daba6

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

examples/pylab_examples/date_index_formatter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"""
1010

1111
from __future__ import print_function
12-
import numpy
12+
import numpy as np
1313
from matplotlib.mlab import csv2rec
1414
import matplotlib.pyplot as plt
1515
import matplotlib.cbook as cbook
@@ -27,7 +27,7 @@ def __init__(self, dates, fmt='%Y-%m-%d'):
2727

2828
def __call__(self, x, pos=0):
2929
'Return the label for time x at position pos'
30-
ind = int(round(x))
30+
ind = int(np.round(x))
3131
if ind >= len(self.dates) or ind < 0:
3232
return ''
3333

@@ -37,6 +37,6 @@ def __call__(self, x, pos=0):
3737

3838
fig, ax = plt.subplots()
3939
ax.xaxis.set_major_formatter(formatter)
40-
ax.plot(numpy.arange(len(r)), r.close, 'o-')
40+
ax.plot(np.arange(len(r)), r.close, 'o-')
4141
fig.autofmt_xdate()
4242
plt.show()

lib/matplotlib/backends/backend_agg.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
210210

211211
#print x, y, int(x), int(y), s
212212
self._renderer.draw_text_image(
213-
font, round(x - xd + xo), round(y + yd + yo) + 1, angle, gc)
213+
font, np.round(x - xd + xo), np.round(y + yd + yo) + 1, angle, gc)
214214

215215
def get_text_width_height_descent(self, s, prop, ismath):
216216
"""
@@ -257,8 +257,8 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
257257
w, h, d = self.get_text_width_height_descent(s, prop, ismath)
258258
xd = d * sin(radians(angle))
259259
yd = d * cos(radians(angle))
260-
x = round(x + xd)
261-
y = round(y + yd)
260+
x = np.round(x + xd)
261+
y = np.round(y + yd)
262262

263263
self._renderer.draw_text_image(Z, x, y, angle, gc)
264264

lib/matplotlib/image.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def flush_images():
152152
gc = renderer.new_gc()
153153
gc.set_clip_rectangle(parent.bbox)
154154
gc.set_clip_path(parent.get_clip_path())
155-
renderer.draw_image(gc, round(l), round(b), data)
155+
renderer.draw_image(gc, np.round(l), np.round(b), data)
156156
gc.restore()
157157
del image_group[:]
158158

lib/matplotlib/ticker.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,8 +1760,8 @@ def _raw_ticks(self, vmin, vmax):
17601760
step = max(1, step)
17611761
best_vmin = (_vmin // step) * step
17621762

1763-
low = round(Base(step).le(_vmin - best_vmin) / step)
1764-
high = round(Base(step).ge(_vmax - best_vmin) / step)
1763+
low = np.round(Base(step).le(_vmin - best_vmin) / step)
1764+
high = np.round(Base(step).ge(_vmax - best_vmin) / step)
17651765
ticks = np.arange(low, high + 1) * step + best_vmin + offset
17661766
nticks = ((ticks <= vmax) & (ticks >= vmin)).sum()
17671767
if nticks >= self._min_n_ticks:

0 commit comments

Comments
 (0)