From f7d1d8188c848e38e210bfa4fd0d1b308916cae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Thu, 22 Aug 2024 01:53:57 +0200 Subject: [PATCH] Fix NumPy 2.0 deprecations via running ruff (#2580) * Fix NumPy 2.0 deprecations via running `ruff check --select NPY201 --fix --exclude docs/sphinx/rest_substitutions/snippets/python/converted` See https://numpy.org/devdocs/numpy_2_0_migration_guide.html#numpy-2-0-migration-guide * Use `numpy.any` instead of `any` because the latter does not work for multidimensional arrays. --- demo/FloatCanvas.py | 14 +++++++------- samples/floatcanvas/MovingElements.py | 2 +- samples/floatcanvas/MovingTriangle.py | 4 ++-- samples/floatcanvas/PolyEditor.py | 2 +- samples/floatcanvas/ProcessDiagram.py | 2 +- samples/floatcanvas/TextBox.py | 10 +++++----- samples/floatcanvas/Tree.py | 2 +- wx/lib/floatcanvas/FloatCanvas.py | 4 ++-- wx/lib/plot/examples/demo.py | 2 +- wx/lib/plot/plotcanvas.py | 2 +- 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/demo/FloatCanvas.py b/demo/FloatCanvas.py index 48d971cf..f797340d 100644 --- a/demo/FloatCanvas.py +++ b/demo/FloatCanvas.py @@ -720,7 +720,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import x += dx color = "SEA GREEN" - Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float_) + Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float64) R = Canvas.AddPolygon(Points, LineWidth = 2, FillColor = color) R.Name = color + " Polygon" R.Bind(FloatCanvas.EVT_FC_RIGHT_DOWN, self.RectGotHitRight) @@ -729,7 +729,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import x += dx color = "Red" - Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float_) + Points = N.array(( (x, y), (x, y+2.*h/3), (x+w, y+h), (x+w, y+h/2.), (x + 2.*w/3, y+h/2.), (x + 2.*w/3,y) ), N.float64) R = Canvas.AddPointSet(Points, Diameter = 4, Color = color) R.Name = "PointSet" R.Bind(FloatCanvas.EVT_FC_LEFT_DOWN, self.PointSetGotHit) @@ -1139,7 +1139,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import Family = wx.FONTFAMILY_ROMAN, Alignment = "right" ) - Point = N.array((100, -20), N.float_) + Point = N.array((100, -20), N.float64) Box = Canvas.AddScaledTextBox("Here is even more auto wrapped text. This time the line spacing is set to 0.8. \n\nThe Padding is set to 0.", Point, Size = 3, @@ -1153,7 +1153,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import ) Canvas.AddPoint(Point, "Red", 2) - Point = N.array((0, -40), N.float_) + Point = N.array((0, -40), N.float64) # Point = N.array((0, 0), N.float_) for Position in ["tl", "bl", "tr", "br"]: # for Position in ["br"]: @@ -1172,7 +1172,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import ) Canvas.AddPoint(Point, "Red", 4) - Point = N.array((-20, 60), N.float_) + Point = N.array((-20, 60), N.float64) Box = Canvas.AddScaledTextBox("Here is some\ncentered\ntext", Point, Size = 4, @@ -1188,7 +1188,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import LineSpacing = 0.8 ) - Point = N.array((-20, 20), N.float_) + Point = N.array((-20, 20), N.float64) Box = Canvas.AddScaledTextBox("Here is some\nright aligned\ntext", Point, Size = 4, @@ -1203,7 +1203,7 @@ def BuildDrawFrame(): # this gets called when needed, rather than on import LineSpacing = 0.8 ) - Point = N.array((100, -60), N.float_) + Point = N.array((100, -60), N.float64) Box = Canvas.AddScaledTextBox("Here is some auto wrapped text. This time it is centered, rather than right aligned.\n\nThe Padding is set to 2.", Point, Size = 3, diff --git a/samples/floatcanvas/MovingElements.py b/samples/floatcanvas/MovingElements.py index 40db2858..75229c07 100644 --- a/samples/floatcanvas/MovingElements.py +++ b/samples/floatcanvas/MovingElements.py @@ -160,7 +160,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin): Points = N.array(((0, c), ( L/2.0, -c/2.0), (-L/2.0, -c/2.0)), - N.float_) + N.float64) Points += XY return Points diff --git a/samples/floatcanvas/MovingTriangle.py b/samples/floatcanvas/MovingTriangle.py index f3277f21..82266246 100644 --- a/samples/floatcanvas/MovingTriangle.py +++ b/samples/floatcanvas/MovingTriangle.py @@ -64,7 +64,7 @@ class TriangleShape1(FC.Polygon, ShapeMixin): Points = N.array(((0, c), ( L/2.0, -c/2.0), (-L/2.0, -c/2.0)), - N.float_) + N.float64) Points += XY return Points @@ -104,7 +104,7 @@ class DrawFrame(wx.Frame): Points = N.array(((0,0), (1,0), (0.5, 1)), - N.float_) + N.float64) data = (( (0,0), 1), ( (3,3), 2), diff --git a/samples/floatcanvas/PolyEditor.py b/samples/floatcanvas/PolyEditor.py index 55b1af42..270daa83 100644 --- a/samples/floatcanvas/PolyEditor.py +++ b/samples/floatcanvas/PolyEditor.py @@ -112,7 +112,7 @@ class DrawFrame(wx.Frame): dc.SetPen(wx.Pen('WHITE', 2, wx.SHORT_DASH)) dc.SetLogicalFunction(wx.XOR) if self.SelectedPointNeighbors is None: - self.SelectedPointNeighbors = N.zeros((3,2), N.float_) + self.SelectedPointNeighbors = N.zeros((3,2), N.float64) #fixme: This feels very inelegant! if Index == 0: self.SelectedPointNeighbors[0] = self.SelectedPoly.Points[-1] diff --git a/samples/floatcanvas/ProcessDiagram.py b/samples/floatcanvas/ProcessDiagram.py index cf860905..f67f8955 100644 --- a/samples/floatcanvas/ProcessDiagram.py +++ b/samples/floatcanvas/ProcessDiagram.py @@ -212,7 +212,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin): Points = N.array(((0, c), ( L/2.0, -c/2.0), (-L/2.0, -c/2.0)), - N.float_) + N.float64) Points += XY return Points diff --git a/samples/floatcanvas/TextBox.py b/samples/floatcanvas/TextBox.py index 5badeb1d..29db917c 100644 --- a/samples/floatcanvas/TextBox.py +++ b/samples/floatcanvas/TextBox.py @@ -188,7 +188,7 @@ class DrawFrame(wx.Frame): Family = wx.ROMAN, Alignment = "right" ) - Point = N.array((100, -20), N.float_) + Point = N.array((100, -20), N.float64) Box = Canvas.AddScaledTextBox("Here is even more auto wrapped text. This time the line spacing is set to 0.8. \n\nThe Padding is set to 0.", Point, Size = 3, @@ -202,7 +202,7 @@ class DrawFrame(wx.Frame): ) Canvas.AddPoint(Point, "Red", 2) - Point = N.array((0, -40), N.float_) + Point = N.array((0, -40), N.float64) # Point = N.array((0, 0), N.float_) for Position in ["tl", "bl", "tr", "br"]: # for Position in ["br"]: @@ -221,7 +221,7 @@ class DrawFrame(wx.Frame): ) Canvas.AddPoint(Point, "Red", 4) - Point = N.array((-20, 60), N.float_) + Point = N.array((-20, 60), N.float64) Box = Canvas.AddScaledTextBox("Here is some\ncentered\ntext", Point, Size = 4, @@ -237,7 +237,7 @@ class DrawFrame(wx.Frame): LineSpacing = 0.8 ) - Point = N.array((-20, 20), N.float_) + Point = N.array((-20, 20), N.float64) Box = Canvas.AddScaledTextBox("Here is some\nright aligned\ntext", Point, Size = 4, @@ -252,7 +252,7 @@ class DrawFrame(wx.Frame): LineSpacing = 0.8 ) - Point = N.array((100, -60), N.float_) + Point = N.array((100, -60), N.float64) Box = Canvas.AddScaledTextBox("Here is some auto wrapped text. This time it is centered, rather than right aligned.\n\nThe Padding is set to 2.", Point, Size = 3, diff --git a/samples/floatcanvas/Tree.py b/samples/floatcanvas/Tree.py index 7757651f..4c75ac6a 100644 --- a/samples/floatcanvas/Tree.py +++ b/samples/floatcanvas/Tree.py @@ -204,7 +204,7 @@ class TriangleShape1(FC.Polygon, MovingObjectMixin): Points = N.array(((0, c), ( L/2.0, -c/2.0), (-L/2.0, -c/2.0)), - N.float_) + N.float64) Points += XY return Points diff --git a/wx/lib/floatcanvas/FloatCanvas.py b/wx/lib/floatcanvas/FloatCanvas.py index a0c316cd..ebdd689f 100644 --- a/wx/lib/floatcanvas/FloatCanvas.py +++ b/wx/lib/floatcanvas/FloatCanvas.py @@ -601,7 +601,7 @@ class FloatCanvas(wx.Panel): """ - if N.sometrue(self.PanelSize <= 2 ): + if N.any(self.PanelSize <= 2 ): # it's possible for this to get called before being properly initialized. return if self.Debug: start = clock() @@ -779,7 +779,7 @@ class FloatCanvas(wx.Panel): BoundingBox = self.BoundingBox if (BoundingBox is not None) and (not BoundingBox.IsNull()): self.ViewPortCenter = N.array(((BoundingBox[0,0]+BoundingBox[1,0])/2, - (BoundingBox[0,1]+BoundingBox[1,1])/2 ),N.float_) + (BoundingBox[0,1]+BoundingBox[1,1])/2 ),N.float64) self.MapProjectionVector = self.ProjectionFun(self.ViewPortCenter) # Compute the new Scale BoundingBox = BoundingBox*self.MapProjectionVector # this does need to make a copy! diff --git a/wx/lib/plot/examples/demo.py b/wx/lib/plot/examples/demo.py index 74312b77..ce1767b1 100644 --- a/wx/lib/plot/examples/demo.py +++ b/wx/lib/plot/examples/demo.py @@ -231,7 +231,7 @@ def _draw8Objects(): """ Box plot """ - data1 = np.array([np.NaN, 337, 607, 583, 512, 531, 558, 381, 621, 574, + data1 = np.array([np.nan, 337, 607, 583, 512, 531, 558, 381, 621, 574, 538, 577, 679, 415, 454, 417, 635, 319, 350, 183, 863, 337, 607, 583, 512, 531, 558, 381, 621, 574, 538, 577, 679, 415, 454, 417, 635, 319, 350, 97]) diff --git a/wx/lib/plot/plotcanvas.py b/wx/lib/plot/plotcanvas.py index 0e1e8a0e..b9f65d8d 100644 --- a/wx/lib/plot/plotcanvas.py +++ b/wx/lib/plot/plotcanvas.py @@ -2044,7 +2044,7 @@ class PlotCanvas(wx.Panel): """ if self.last_PointLabel is not None: # compare pointXY - if np.sometrue( + if np.any( mDataDict["pointXY"] != self.last_PointLabel["pointXY"]): # closest changed self._drawPointLabel(self.last_PointLabel) # erase old