From 2c82a84f68b6e79bd3be5adc9b2388c3c6fc99be Mon Sep 17 00:00:00 2001 From: Nils Nemitz Date: Tue, 23 Mar 2021 01:08:31 +0900 Subject: [PATCH] Do not use clip_array on scalars (use clip_scalar instead) --- pyqtgraph/functions.py | 3 +++ pyqtgraph/graphicsItems/PlotDataItem.py | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pyqtgraph/functions.py b/pyqtgraph/functions.py index bd86356e..5ca74a58 100644 --- a/pyqtgraph/functions.py +++ b/pyqtgraph/functions.py @@ -998,6 +998,9 @@ def solveBilinearTransform(points1, points2): return matrix +def clip_scalar(val, vmin, vmax): + """ convenience function to avoid using np.clip for scalar values """ + return vmin if val < vmin else vmax if val > vmax else val def clip_array(arr, vmin, vmax, out=None): # replacement for np.clip due to regression in diff --git a/pyqtgraph/graphicsItems/PlotDataItem.py b/pyqtgraph/graphicsItems/PlotDataItem.py index 73eaedbf..e0602463 100644 --- a/pyqtgraph/graphicsItems/PlotDataItem.py +++ b/pyqtgraph/graphicsItems/PlotDataItem.py @@ -679,8 +679,8 @@ class PlotDataItem(GraphicsObject): # workaround for slowdown from numpy deprecation issues in 1.17 to 1.20+ # x0 = np.clip(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1) # x1 = np.clip(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1) - x0 = fn.clip_array(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1) - x1 = fn.clip_array(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1) + x0 = fn.clip_scalar(int((range.left()-x[0])/dx) - 1*ds, 0, len(x)-1) + x1 = fn.clip_scalar(int((range.right()-x[0])/dx) + 2*ds, 0, len(x)-1) # if data has been clipped too strongly (in case of non-uniform # spacing of x-values), refine the clipping region as required @@ -688,11 +688,11 @@ class PlotDataItem(GraphicsObject): # best case performance: O(1) if x[x0] > range.left(): x0 = np.searchsorted(x, range.left()) - 1*ds - x0 = fn.clip_array(x0, 0, len(x)) # workaround + x0 = fn.clip_scalar(x0, 0, len(x)) # workaround # x0 = np.clip(x0, 0, len(x)) if x[x1] < range.right(): x1 = np.searchsorted(x, range.right()) + 2*ds - x1 = fn.clip_array(x1, 0, len(x)) + x1 = fn.clip_scalar(x1, 0, len(x)) # x1 = np.clip(x1, 0, len(x)) x = x[x0:x1] y = y[x0:x1]