diff --git a/gui/wxpython/wxplot/profile.py b/gui/wxpython/wxplot/profile.py index 1941022fb59..1e79379b08b 100644 --- a/gui/wxpython/wxplot/profile.py +++ b/gui/wxpython/wxplot/profile.py @@ -472,7 +472,7 @@ def OnStats(self, event): statstr = "Profile of %s\n\n" % rast iterable = (i[1] for i in self.raster[r]["datalist"]) - a = np.fromiter(iterable, np.float) + a = np.fromiter(iterable, float) statstr += "n: %f\n" % a.size statstr += "minimum: %f\n" % np.amin(a) diff --git a/pyproject.toml b/pyproject.toml index b4ff3583cf4..b9739df49c9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -352,7 +352,6 @@ ignore = [ "gui/wxpython/web_services/dialogs.py" = ["INT003"] "gui/wxpython/web_services/widgets.py" = ["INT003"] "gui/wxpython/wxgui.py" = ["INT002"] -"gui/wxpython/wxplot/profile.py" = ["NPY001"] "lib/imagery/testsuite/test_imagery_sigsetfile.py" = ["FURB152"] "lib/init/grass.py" = ["INT003"] "python/grass/__init__.py" = ["PYI056"] @@ -365,14 +364,11 @@ ignore = [ "python/grass/jupyter/tests/reprojection_renderer_test.py" = ["PT013"] "python/grass/jupyter/testsuite/interactivemap_test.py" = ["PGH004"] "python/grass/jupyter/testsuite/map_test.py" = ["PGH004"] -"python/grass/pygrass/raster/__init__.py" = ["NPY002"] "python/grass/pygrass/raster/category.py" = ["INT002"] -"python/grass/pygrass/raster/testsuite/test_numpy.py" = ["NPY002"] "python/grass/pygrass/vector/__init__.py" = ["INT003"] "python/grass/pygrass/vector/geometry.py" = ["PYI024"] "python/grass/pygrass/vector/sql.py" = ["FLY002"] -"python/grass/pygrass/vector/testsuite/test_table.py" = ["NPY002", "PLW0108"] -"python/grass/pygrass/vector/testsuite/test_vector3d.py" = ["NPY002"] +"python/grass/pygrass/vector/testsuite/test_table.py" = ["PLW0108"] "python/grass/script/raster.py" = ["INT003"] "python/grass/temporal/abstract_space_time_dataset.py" = ["INT003"] "python/grass/temporal/aggregation.py" = ["INT003"] diff --git a/python/grass/pygrass/raster/__init__.py b/python/grass/pygrass/raster/__init__.py index 818d9576514..0356513e017 100644 --- a/python/grass/pygrass/raster/__init__.py +++ b/python/grass/pygrass/raster/__init__.py @@ -580,15 +580,11 @@ def close(self, rm_temp_files=True): def random_map_only_columns(mapname, mtype, overwrite=True, factor=100): region = Region() random_map = RasterRow(mapname) + rng = np.random.default_rng() row_buf = Buffer( (region.cols,), mtype, - buffer=( - np.random.random( - region.cols, - ) - * factor - ).data, + buffer=(rng.random(region.cols) * factor).data, ) random_map.open("w", mtype, overwrite) for _ in range(region.rows): @@ -601,16 +597,12 @@ def random_map(mapname, mtype, overwrite=True, factor=100): region = Region() random_map = RasterRow(mapname) random_map.open("w", mtype, overwrite) + rng = np.random.default_rng() for _ in range(region.rows): row_buf = Buffer( (region.cols,), mtype, - buffer=( - np.random.random( - region.cols, - ) - * factor - ).data, + buffer=(rng.random(region.cols) * factor).data, ) random_map.put_row(row_buf) random_map.close() diff --git a/python/grass/pygrass/raster/testsuite/test_numpy.py b/python/grass/pygrass/raster/testsuite/test_numpy.py index a2a6e1cdd26..5f0b2309544 100644 --- a/python/grass/pygrass/raster/testsuite/test_numpy.py +++ b/python/grass/pygrass/raster/testsuite/test_numpy.py @@ -6,7 +6,7 @@ from grass.gunittest.case import TestCase from grass.gunittest.main import test -from numpy.random import random +from numpy.random import default_rng from grass.pygrass.raster import raster2numpy, numpy2raster, RasterRow @@ -49,8 +49,8 @@ def test_len(self): self.assertTrue(len(self.numpy_obj[0]), 60) def test_write(self): - ran = random([40, 60]) - numpy2raster(ran, "FCELL", self.name, True) + rng = default_rng() + numpy2raster(rng.random([40, 60]), "FCELL", self.name, True) self.assertTrue(check_raster(self.name)) diff --git a/python/grass/pygrass/vector/testsuite/test_table.py b/python/grass/pygrass/vector/testsuite/test_table.py index d603817de98..1acb410a10f 100644 --- a/python/grass/pygrass/vector/testsuite/test_table.py +++ b/python/grass/pygrass/vector/testsuite/test_table.py @@ -18,11 +18,12 @@ # dictionary that generate random data +RNG = np.random.default_rng() COL2VALS = { - "INT": lambda n: np.random.randint(9, size=n), - "INTEGER": lambda n: np.random.randint(9, size=n), + "INT": lambda n: RNG.integers(low=0, high=9, size=n), + "INTEGER": lambda n: RNG.integers(low=0, high=9, size=n), "INTEGER PRIMARY KEY": lambda n: np.arange(1, n + 1, dtype=int), - "REAL": lambda n: np.random.rand(n), + "REAL": lambda n: RNG.random(n), "TEXT": lambda n: np.array([randstr() for _ in range(n)]), } diff --git a/python/grass/pygrass/vector/testsuite/test_vector3d.py b/python/grass/pygrass/vector/testsuite/test_vector3d.py index 16ee0fd969e..796f85ca529 100644 --- a/python/grass/pygrass/vector/testsuite/test_vector3d.py +++ b/python/grass/pygrass/vector/testsuite/test_vector3d.py @@ -19,11 +19,12 @@ def generate_coordinates(number, bbox=None, with_z=False): """Return 2 or 3 random arrays of coordinates""" + rng = np.random.default_rng() bbox = Region() if bbox is None else bbox - x = bbox.south + (bbox.north - bbox.south) * np.random.random(number) - y = bbox.west + (bbox.east - bbox.west) * np.random.random(number) + x = bbox.south + (bbox.north - bbox.south) * rng.random(number) + y = bbox.west + (bbox.east - bbox.west) * rng.random(number) if with_z: - z = np.random.random(number) * 1000 + z = rng.random(number) * 1000 return x, y, z return x, y