The foo[count:-count] gotcha: -0 silently empties your array slice

theshawwn · x · 2026-10-03

A subtle slicing bug: 0 and -0 are numerically equal, so foo[count:-count] becomes foo[0:0] when count is 0, silently returning an empty array.

The safe expression is foo[count:foo.shape[0]-count]. The author muses that it would be nice if -0 could mean "end of array".

Original post →

More from coding & agent

coding & agent channel →