Skip to content

fix: give rankfilter a default rank of median - #241

Merged
petercorke merged 2 commits into
mainfrom
bug/rankfilter-default
Nov 22, 2026
Merged

petercorke merged 2 commits into
mainfrom
bug/rankfilter-default

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Image.rankfilter() had rank=-1 as its default, but the check that follows rejects any rank below 0 with ValueError("rank must be >= 0"). So a call without rank, such as img.rankfilter(h=1), always raised, and the default was never usable. The deprecated Image.rank() has the same default.

rank now defaults to "median", the most common rank filter. Passing rank explicitly behaves exactly as before. rank is not made required, so the signature and positional calls are unchanged. The docstring documents the default and has a .. versionchanged:: 2.5.0 note.

Tests

Two new tests: the default gives the same result as scipy.ndimage.median_filter and as rank="median", and the deprecated rank() has the same default. tests/test_image_spatial_extra.py passes and mypy reports no errors. I have not run the full suite locally. CI will.

This change was written with AI assistance (Claude Code) and I have reviewed the diff.

🤖 Generated with Claude Code

The default rank=-1 was always rejected by the check that follows, so
rankfilter() and the deprecated rank() raised unless rank was given.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit de734f9 into main Nov 22, 2026
34 checks passed
@petercorke
petercorke deleted the bug/rankfilter-default branch November 22, 2026 22:30
@github-actions github-actions Bot mentioned this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant