Skip to content

fix: validate Butterworth filter inputs - #14979

Merged
cclauss merged 1 commit into
TheAlgorithms:masterfrom
rushijagani-dev:fix-butterworth-validation
Sep 5, 2026
Merged

cclauss merged 1 commit into
TheAlgorithms:masterfrom
rushijagani-dev:fix-butterworth-validation

Conversation

@rushijagani-dev

@rushijagani-dev rushijagani-dev commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Describe your change:

Fixes #12379

Adds shared validation for Butterworth filter factory inputs before coefficients are calculated. The change rejects non-positive frequencies, samplerates, and Q factors with ValueError, and rejects cutoff frequencies at or above the Nyquist limit. This prevents invalid high-pass/low-pass/etc. calls from returning unusable coefficients or falling through to ZeroDivisionError. The new doctests cover valid input and the expected error cases.

Validation:

  • python3 -m doctest -v audio_filters/butterworth_filter.py - passed, 19 doctests passed.
  • python3 -m pytest audio_filters/butterworth_filter.py - passed, 8 tests passed.
  • uvx ruff check audio_filters/butterworth_filter.py - passed.
  • python3 -m compileall -q audio_filters/butterworth_filter.py - passed.
  • git diff --check - passed.

Blockers:

  • uv run --with=pytest pytest audio_filters/butterworth_filter.py could not start locally because no Python >=3.14 interpreter is available on this machine, and uv python install 3.14 reported no macOS/aarch64 download for that request.
  • python3 -m pytest audio_filters collected the touched file successfully, but the broader package run is blocked locally by missing optional dependencies in unrelated files: audio_filters/show_response.py requires matplotlib, and after ignoring it, audio_filters/iir_filter.py requires scipy for its doctest.
  • uvx ruff check . with local ruff 0.16.0 reports three unrelated existing findings outside this PR's file; the touched file passes the same ruff command.
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@cclauss cclauss left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cclauss
cclauss merged commit 38e0923 into TheAlgorithms:master Sep 5, 2026
1 check passed
@algorithms-keeper algorithms-keeper Bot removed awaiting reviews This PR is ready to be reviewed labels Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement This PR modified some existing files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Find:audio_filters/butterworth_filter.py issure

2 participants