Skip to content

Commit

Permalink
Replace np.alltrue with np.all for np v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
ankith26 committed Jun 17, 2024
1 parent e14abb1 commit 875ed65
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
8 changes: 4 additions & 4 deletions test/pixelcopy_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ def test_surface_to_array_3d(self):

def test_map_array(self):
try:
from numpy import array, zeros, uint8, int32, alltrue
from numpy import array, zeros, uint8, int32, all as np_all
except ImportError:
return

Expand All @@ -545,15 +545,15 @@ def test_map_array(self):
target = zeros((5, 7), int32)
map_array(target, color, surf)

self.assertTrue(alltrue(target == surf.map_rgb(color)))
self.assertTrue(np_all(target == surf.map_rgb(color)))

# array column stripes
stripe = array([[2, 5, 7], [11, 19, 23], [37, 53, 101]], uint8)
target = zeros((4, stripe.shape[0]), int32)
map_array(target, stripe, surf)
target_stripe = array([surf.map_rgb(c) for c in stripe], int32)

self.assertTrue(alltrue(target == target_stripe))
self.assertTrue(np_all(target == target_stripe))

# array row stripes
stripe = array(
Expand All @@ -563,7 +563,7 @@ def test_map_array(self):
map_array(target, stripe, surf)
target_stripe = array([[surf.map_rgb(c)] for c in stripe[:, 0]], int32)

self.assertTrue(alltrue(target == target_stripe))
self.assertTrue(np_all(target == target_stripe))

# mismatched shape
w = 4
Expand Down
8 changes: 4 additions & 4 deletions test/sndarray_test.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import unittest

from numpy import int8, int16, uint8, uint16, float32, array, alltrue
from numpy import int8, int16, uint8, uint16, float32, array, all as np_all

import pygame
import pygame.sndarray
Expand Down Expand Up @@ -28,7 +28,7 @@ def check_array(size, channels, test_data):
arr = pygame.sndarray.array(snd)
self._assert_compatible(arr, size)
self.assertTrue(
alltrue(arr == srcarr),
np_all(arr == srcarr),
"size: %i\n%s\n%s" % (size, arr, test_data),
)
finally:
Expand Down Expand Up @@ -71,7 +71,7 @@ def check_sound(size, channels, test_data):
snd = pygame.sndarray.make_sound(srcarr)
arr = pygame.sndarray.samples(snd)
self.assertTrue(
alltrue(arr == srcarr),
np_all(arr == srcarr),
"size: %i\n%s\n%s" % (size, arr, test_data),
)
finally:
Expand Down Expand Up @@ -110,7 +110,7 @@ def check_sample(size, channels, test_data):
samples[...] = test_data
arr = pygame.sndarray.array(snd)
self.assertTrue(
alltrue(samples == arr),
np_all(samples == arr),
"size: %i\n%s\n%s" % (size, arr, test_data),
)
finally:
Expand Down
12 changes: 6 additions & 6 deletions test/surfarray_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
zeros,
float32,
float64,
alltrue,
all as np_all,
rint,
arange,
)
Expand Down Expand Up @@ -235,15 +235,15 @@ def test_array_alpha(self):
),
)
else:
self.assertTrue(alltrue(arr == 255))
self.assertTrue(np_all(arr == 255))

# No per-pixel alpha when blanket alpha is None.
for surf in targets:
blanket_alpha = surf.get_alpha()
surf.set_alpha(None)
arr = pygame.surfarray.array_alpha(surf)
self.assertTrue(
alltrue(arr == 255),
np_all(arr == 255),
"All alpha values should be 255 when"
" surf.set_alpha(None) has been set."
" bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
Expand All @@ -257,12 +257,12 @@ def test_array_alpha(self):
arr = pygame.surfarray.array_alpha(surf)
if surf.get_masks()[3]:
self.assertFalse(
alltrue(arr == 255),
np_all(arr == 255),
"bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
)
else:
self.assertTrue(
alltrue(arr == 255),
np_all(arr == 255),
"bitsize: %i, flags: %i" % (surf.get_bitsize(), surf.get_flags()),
)
surf.set_alpha(blanket_alpha)
Expand Down Expand Up @@ -290,7 +290,7 @@ def test_array_colorkey(self):
p = [surf.unmap_rgb(surf.map_rgb(c)) for c in p]
surf.set_colorkey(None)
arr = pygame.surfarray.array_colorkey(surf)
self.assertTrue(alltrue(arr == 255))
self.assertTrue(np_all(arr == 255))

for i in range(1, len(palette)):
surf.set_colorkey(p[i])
Expand Down

0 comments on commit 875ed65

Please sign in to comment.