A community-maintained Python framework for creating mathematical animations.
Replace legacy numpy usage ruff rule NPY002 (#4516)
Christian Claussdc4a8bb741de
diff --git a/manim/mobject/vector_field.py b/manim/mobject/vector_field.pyindex ff153c7a5..ec3443360 100644--- a/manim/mobject/vector_field.py+++ b/manim/mobject/vector_field.py@@ -791,13 +791,13 @@ class StreamLines(VectorField):self.stroke_width = stroke_widthhalf_noise = self.noise_factor / 2- np.random.seed(0)+ rng = np.random.default_rng(0)start_points = np.array([(x - half_noise) * RIGHT+ (y - half_noise) * UP+ (z - half_noise) * OUT- + self.noise_factor * np.random.random(3)+ + self.noise_factor * rng.random(3)for n in range(self.n_repeats)for x in np.arange(*self.x_range)for y in np.arange(*self.y_range)diff --git a/manim/scene/scene.py b/manim/scene/scene.pyindex 2a12f048d..ab250d7c9 100644--- a/manim/scene/scene.py+++ b/manim/scene/scene.py@@ -221,7 +221,7 @@ class Scene:self.foreground_mobjects: list[Mobject] = []if self.random_seed is not None:random.seed(self.random_seed)- np.random.seed(self.random_seed)+ np.random.default_rng(self.random_seed)@propertydef camera(self) -> Camera | OpenGLCamera:diff --git a/manim/utils/qhull.py b/manim/utils/qhull.pyindex 9e3b32956..4a7bc385b 100644--- a/manim/utils/qhull.py+++ b/manim/utils/qhull.py@@ -114,8 +114,9 @@ class QuickHull:def initialize(self, points: PointND_Array) -> None:# Sample Points+ rng = np.random.default_rng()simplex = points[- np.random.choice(points.shape[0], points.shape[1] + 1, replace=False)+ rng.choice(points.shape[0], points.shape[1] + 1, replace=False)]self.unclaimed = pointsnew_internal: PointND = np.mean(simplex, axis=0)diff --git a/pyproject.toml b/pyproject.tomlindex c841db3dc..cc6b9024c 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -151,6 +151,7 @@ select = ["E","F","I",+ "NPY","PERF","PGH","PT",diff --git a/tests/module/mobject/test_image.py b/tests/module/mobject/test_image.pyindex a79fce5b8..ef00eb75b 100644--- a/tests/module/mobject/test_image.py+++ b/tests/module/mobject/test_image.py@@ -6,7 +6,8 @@ from manim import ImageMobject@pytest.mark.parametrize("dtype", [np.uint8, np.uint16])def test_invert_image(dtype):- array = (255 * np.random.rand(10, 10, 4)).astype(dtype)+ rng = np.random.default_rng()+ array = (255 * rng.random((10, 10, 4))).astype(dtype)image = ImageMobject(array, pixel_array_dtype=dtype, invert=True)assert image.pixel_array.dtype == dtypediff --git a/tests/module/utils/test_space_ops.py b/tests/module/utils/test_space_ops.pyindex 13584c797..06bd59680 100644--- a/tests/module/utils/test_space_ops.py+++ b/tests/module/utils/test_space_ops.py@@ -64,7 +64,8 @@ def test_angle_of_vector():def test_angle_of_vector_vectorized():- vec = np.random.randn(4, 10)+ rng = np.random.default_rng()+ vec = rng.standard_normal((4, 10))ref = [np.angle(complex(*v[:2])) for v in vec.T]np.testing.assert_array_equal(ref, angle_of_vector(vec))