Skip to content

MAINT: fix two more issues with padding length 0 and size-0 axis input - #859

Open
rgommers wants to merge 2 commits into
PyWavelets:mainfrom
rgommers:bugfix/pad-zero-width
Open

MAINT: fix two more issues with padding length 0 and size-0 axis input#859
rgommers wants to merge 2 commits into
PyWavelets:mainfrom
rgommers:bugfix/pad-zero-width

Conversation

@rgommers

Copy link
Copy Markdown
Member

This is a follow-up to gh-854.

Used Claude Opus 5.0 to review gh-854 and it identified these two similar cases - fix them while we're at it. Claude also wrote the code, verified by me. This isn't very important as a real-world issue, but may as well get it all handled consistently.

…mples

A slope cannot be determined from a single sample, and pywt.pad computed one
anyway from whatever numpy.pad had left in the padding buffer, giving a ramp
away from the only known value. With a pad width of 0 there was no buffer to
read from and it raised an IndexError instead.

The transforms already handle this: convolution.template.c demotes MODE_SMOOTH
to MODE_CONSTANT_EDGE when the input has fewer than 2 samples. Do the same in
pad(), and leave a zero-length axis untouched as there is nothing to extend
from.
The reflected segments that the mode flips the sign of are as wide as the
unpadded signal, so for a zero-size axis `r_edge += seg_width` never advanced
and the loop spun forever. Only reachable with a pad width of 0, as numpy.pad
rejects reflecting an empty axis otherwise. There is nothing to reflect in that
case, so return early.

Also assert what 'periodization' does for a zero pad width instead of skipping
it, since it is the one mode that is deliberately not the identity there.
@rgommers rgommers added this to the v1.10.0 milestone Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant