CLI: non-finite threshold values are accepted and NaN silently disables the score gate
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The threshold is parsed in parse_args in src/crapper/cli.py (around lines 134-142), which calls float(raw) and only catches ValueError. The gate is _threshold_status (around lines 294-304), where max(scored) > options.threshold is false for NaN. Start by running the reproduction script in the issue, then reject NaN and positive infinity during parsing with a nonzero usage error. Done means --threshold nan and --threshold inf fail before analysis, and a finite threshold of 100 still returns status 2 for a score of 1,000,000.
Written by the indexing model from the issue text.
Description
Summary
--threshold nan is accepted as an analysis option. Since every greater-than comparison against NaN is false, even a scored entry of 1,000,000 passes. Positive infinity is also accepted without finite-value validation and passes every finite score.
Verified against default branch master at c757ec79a6c15dc815238bbd9c2f4601eb54d3cc.
Minimal reproduction
Requires Git and Python 3.9+ only. No package installation or project imports. This extracts the named source definitions with the standard-library AST and exercises them directly; it does not run the full CLI or a language parser.
work=$(mktemp -d)
git clone https://github.com/unclebob/crapper.git "$work/crapper"
git -C "$work/crapper" checkout --detach c757ec79a6c15dc815238bbd9c2f4601eb54d3cc
python3 - "$work/crapper" <<'PY'
import ast
import re
import sys
from dataclasses import dataclass, field
from pathlib import Path
from tempfile import TemporaryDirectory
from types import SimpleNamespace
checkout = Path(sys.argv[1])
def extract(relative, names):
tree = ast.parse((checkout / relative).read_text())
selected = [node for node in tree.body
if isinstance(node, (ast.FunctionDef, ast.ClassDef))
and node.name in names]
assert {node.name for node in selected} == set(names)
module = ast.Module(body=[ast.ImportFrom(module='__future__',
names=[ast.alias(name='annotations')], level=0)] + selected,
type_ignores=[])
exec(compile(ast.fix_missing_locations(module), relative, 'exec'), globals())
HELP = ''
extract('src/crapper/cli.py', ['Options', '_take', 'parse_args', '_threshold_status'])
entries = [SimpleNamespace(crap=1000000.0)]
for raw in ['nan', 'NaN', 'inf', 'Infinity', '100']:
options = parse_args(['--threshold', raw])
status = _threshold_status(options, entries)
print(raw, 'action=' + options.action,
'threshold=' + str(options.threshold), 'gate_status=' + str(status))
assert options.action == 'analyze'
assert status == (2 if raw == '100' else 0)
PY
Expected
Reject non-finite threshold values during argument parsing with a nonzero usage/error status. Do not start analysis for NaN or infinity. A finite threshold of 100 should still reject a score of 1,000,000.
Actual
nan, NaN, inf, and Infinity all parse with action analyze and return gate status 0 for the scored entry. The finite control 100 returns status 2.
The assertions in the reproduction confirm the current incorrect behavior, rather than asserting the intended fix.
Cause and source
parse_args converts the raw string with float(raw) and checks only ValueError. _threshold_status uses max(scored) > options.threshold, which is false for NaN. No finite-value check intervenes.
- https://github.com/unclebob/crapper/blob/c757ec79a6c15dc815238bbd9c2f4601eb54d3cc/src/crapper/cli.py#L134-L142
- https://github.com/unclebob/crapper/blob/c757ec79a6c15dc815238bbd9c2f4601eb54d3cc/src/crapper/cli.py#L294-L304
Suggested regression test
Add argument-parser tests requiring an error for case variants of NaN and positive infinity. Keep finite-value and threshold-equality tests. Assert a finite threshold below the sample score still returns status 2. Negative infinity is already rejected by the option-value handling; the demonstrated missing validation concerns accepted non-finite inputs.
- Dominant language
- Python
- Stars
- 255
- Forks
- 101
- Avg merge
- 7m
- Merged PRs (30d)
- 4
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from unclebob/crapper
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Functions missing from the coverage report score 0% with no warningPossibly taken @warxhead1 claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
All issues in unclebob/crapper
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
AIR-Bench Foundation reads the first letter of the word after "answer" as the model's choicePossibly taken @beartester34 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
modelscope/evalscope#2330 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Distribution plot crashes when a numeric feature is constant in the train or test setPossibly taken @adembilge claimed this today. Openbug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
MAIF/shapash#847 · 1 comment ·
Maintainers usually reply within 10 days