Unsigned ints wrap silently: uint8 a-b, (a+b)/2, and pandas diff()
NumPy 2.5.4, pandas 3.1.0 (pandas results identical on 2.2.3). Array arithmetic on uint8 wraps with no warning. For a=[10,200], b=[20,100]: a-b is [246, 100], so np.abs(a-b) is [246, 100] and not [10, 100]; (a+b)/2 is [15, 22] and not [15, 150]; a*2 is [20, 144]. Only Python-int scalars out of range raise (a+300 gives OverflowError), and a NumPy int32 scalar overflow warns while the array version doesn't. Reductions are safe because sum/mean use a wider accumulator (uint8 img.sum() is uint64). pandas Series.diff() on unsigned dtypes wraps too, before converting to float: uint8 [200, 100].diff() is 156.0, uint16 gives 65436.0 and uint64 gives 1.8e19. Signed int8 [100, -100].diff() is correctly -200.0 (float32), nullable UInt8 gives 156, and np.diff gives 156. pct_change was correct (-0.5). Cast before subtracting image or count data: a.astype(np.int16) - b, or astype('int64') on unsigned columns before diff() (gives -100.0 for the example).