frequent_patterns: reject min_support outside (0, 1] (#864)#1164
Merged
Conversation
`min_support` is documented as a fraction in the half-open interval `(0, 1]`. The validation in apriori / fpgrowth / fpmax / hmine only checked `<= 0`, so values like `min_support=2` would pass through and return an empty DataFrame silently — confusing for users who picked the wrong scale (counts vs fractions, percent vs fraction). Tightens each validator to also reject `> 1.0` with the same message that already advertises the `(0, 1]` interval. Adds a single `test_output4_min_support_above_one_issue_864` to the shared `FPTestEx3All` base class so it runs against all four algorithms. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Code of Conduct
I have read the project's Code of Conduct.
Description
min_supportis documented as a fraction in the half-open interval(0, 1]. The current validators inapriori,fpgrowth,fpmax, andhmineonly rejectmin_support <= 0, so values likemin_support=2silently pass through. The algorithm then returns an empty DataFrame because no fractional support can ever exceed 1, which is confusing for users who picked the wrong scale (counts vs fractions, percent vs fraction).This PR tightens each of the four validators to also reject
> 1.0with the same message that already advertises the(0, 1]interval. The change is localised to the four entry points; nothing else in the algorithms moves.Related issues or pull requests
Fixes #864
Pull Request Checklist
./docs/sources/CHANGELOG.mdfile./mlxtend/frequent_patterns/tests/directory (one shared test inFPTestEx3Allruns against all four algorithms via the existing harness)mlxtend/docs/sources/(not applicable — the existing docstrings already saymin_supportis a fraction in(0, 1])PYTHONPATH='.' pytest ./mlxtend/frequent_patterns -q— 103/103 passedflake8 ./mlxtend(clean) andblack --check(clean)Reproduce BEFORE/AFTER yourself (copy-paste)
What I ran locally
PYTHONPATH=. pytest mlxtend/frequent_patterns -q→ 103/103 passedPYTHONPATH=. pytest mlxtend/frequent_patterns/tests -k "test_output4"→ 4/4 passed (one per algorithm)origin/master's sources: 4/4 fail with "ValueError not raised."flake8+black --checkon touched files → cleanEdge cases tested
min_support = 2(above interval)ValueError: ... within the interval (0, 1]. Got 2.test_output4_min_support_above_one_issue_864(FPTestEx3All; runs against all four algorithms)min_support = 0.0(existing edge)ValueError: ... within the interval (0, 1]. Got 0.0.test_output3(preserved)min_support = 1.0(boundary, valid)FPTestEx1/FPTestEx2min_support = 0.5mlxtend/frequent_patterns/tests(103 passing)Risk / blast radius
Minimal. Affects only the entry-point parameter validation of four functions; nothing in the algorithm bodies changes. Users who were passing absolute counts (e.g.
min_support=5) and getting silent empty results will now get an explicitValueErrorpointing them at the documented fractional interval — strictly more informative.Release note
PR drafted with assistance from Claude Code. The change was reviewed manually against rasbt/mlxtend's source and the existing docstrings, which already specified the
(0, 1]interval. The reproducer block above was used during development; it is the same one a reviewer can paste verbatim.