From 3be8cafff48291933d476b007312e9a38e67e2b9 Mon Sep 17 00:00:00 2001 From: KIU Shueng Chuan Date: Fri, 9 Apr 2021 10:08:03 +0800 Subject: [PATCH] avoid numpy scalar overflow the "offset" argument passed into rescaleData() is typically an element of an ndarray, i.e. it comes from the lower bound value of the "levels" ndarray. as such, arithmetic operations on it can overflow. this triggers a runtime warning in the test suite. the workaround is to convert it to a Python (integer) scalar. --- pyqtgraph/functions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index a2bd15a8..35d394c2 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -1046,7 +1046,9 @@ def _rescaleData_nditer(data_in, scale, offset, work_dtype, out_dtype, clip): # casting to an int32 will lose the fractional part, therefore the # output dtype must be an integer kind. lim_in = np.iinfo(data_in.dtype) - dst_bounds = scale * (lim_in.min - offset), scale * (lim_in.max - offset) + # convert numpy scalar to python scalar to avoid overflow warnings + lo = offset.item(0) if isinstance(offset, np.number) else offset + dst_bounds = scale * (lim_in.min - lo), scale * (lim_in.max - lo) if dst_bounds[1] < dst_bounds[0]: dst_bounds = dst_bounds[1], dst_bounds[0] lim32 = np.iinfo(np.int32)