Merge pull request #183 from ericdill/zero-div-is-bad

MNT: Don't allow divide by zero
This commit is contained in:
Luke Campagnola 2015-07-12 12:08:24 -05:00
commit 0865a3166b
2 changed files with 26 additions and 2 deletions

View File

@ -291,8 +291,8 @@ class ImageItem(GraphicsObject):
y = self.mapToDevice(QtCore.QPointF(0,1)) y = self.mapToDevice(QtCore.QPointF(0,1))
w = Point(x-o).length() w = Point(x-o).length()
h = Point(y-o).length() h = Point(y-o).length()
xds = max(1, int(1/w)) xds = int(1/max(1, w))
yds = max(1, int(1/h)) yds = int(1/max(1, h))
image = fn.downsample(self.image, xds, axis=0) image = fn.downsample(self.image, xds, axis=0)
image = fn.downsample(image, yds, axis=1) image = fn.downsample(image, yds, axis=1)
else: else:

View File

@ -0,0 +1,24 @@
import gc
import weakref
# try:
# import faulthandler
# faulthandler.enable()
# except ImportError:
# pass
from pyqtgraph.Qt import QtCore, QtGui, QtTest
import numpy as np
import pyqtgraph as pg
app = pg.mkQApp()
def test_dividebyzero():
import pyqtgraph as pg
im = pg.image(pg.np.random.normal(size=(100,100)))
im.imageItem.setAutoDownsample(True)
im.view.setRange(xRange=[-5+25, 5e+25],yRange=[-5e+25, 5e+25])
app.processEvents()
QtTest.QTest.qWait(1000)
# must manually call im.imageItem.render here or the exception
# will only exist on the Qt event loop
im.imageItem.render()