A 2D PixelArray with the second dimension equal to 0 should have len(array.shape) == array.ndim == 2.
Instead, it has len(array.shape) == array.ndim == 1; operations treat it as a 1D array.
This behavior does not happen for the first dimension (width) being equal to 0.
from pygame import Surface, PixelArray
surface = Surface((10, 20))
array = PixelArray(surface)
assert array.shape == (10, 20)
assert array[0:0, :].shape == (0, 20)
assert array[:, 0:0].shape == (10, 0) # AssertionError - actual shape is (10,), ndim is 1
This distinction is not trivial; the implicit 'decay' of a 2D array into a 1D one can cause unexpected behavior.
Internally, PixelArrays do not store ndim, and a height (dim1) of 0 is currently the marker for a 1D array.
Suggestion: use an actually invalid sentinel value such as -1 to mark a nonexistent height for a 1D array, instead of 0.
A 2D
PixelArraywith the second dimension equal to0should havelen(array.shape) == array.ndim == 2.Instead, it has
len(array.shape) == array.ndim == 1; operations treat it as a 1D array.This behavior does not happen for the first dimension (width) being equal to 0.
This distinction is not trivial; the implicit 'decay' of a 2D array into a 1D one can cause unexpected behavior.
Internally,
PixelArrays do not storendim, and a height (dim1) of0is currently the marker for a 1D array.Suggestion: use an actually invalid sentinel value such as
-1to mark a nonexistent height for a 1D array, instead of0.