Skip to content

Validate NumPy multinomial sample counts#3226

Merged
FlorianPfaff merged 2 commits into
mainfrom
fix-numpy-multinomial-count-validation
Jun 27, 2026
Merged

Validate NumPy multinomial sample counts#3226
FlorianPfaff merged 2 commits into
mainfrom
fix-numpy-multinomial-count-validation

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

  • validate NumPy backend random.multinomial(..., n=...) before dispatching to NumPy
  • reject boolean, non-scalar, fractional, text, and negative sample counts with explicit errors
  • add regression coverage while preserving integer-like scalar counts

Bug fixed

The NumPy backend already validated pvals, but passed n directly to numpy.random.multinomial. Because Python booleans are integer-like, calls such as random.multinomial(True, [1.0]) were accepted as one draw instead of being rejected consistently with the JAX/PyTorch backend contract.

Testing

  • python -m py_compile /mnt/data/random.py /mnt/data/test_numpy_random_backend.py
  • isolated validator check confirming boolean/fractional/text/non-scalar n inputs are rejected and an integer NumPy scalar is accepted

Full repository pytest was not run because this environment cannot clone the GitHub repository.

@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 69.47s
✅ JSON prettier 7 0 0 0 0.95s
✅ JSON v8r 7 0 0 6.53s
✅ MARKDOWN markdownlint 68 0 0 0 1.72s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.8s
✅ PYTHON black 1045 48 0 0 66.78s
✅ PYTHON isort 1045 69 0 0 5.85s
✅ REPOSITORY checkov yes no no 48.39s
✅ REPOSITORY gitleaks yes no no 8.17s
✅ REPOSITORY git_diff yes no no 0.24s
✅ REPOSITORY secretlint yes no no 31.23s
✅ REPOSITORY syft yes no no 3.09s
✅ REPOSITORY trivy-sbom yes no no 11.85s
✅ REPOSITORY trufflehog yes no no 21.13s
✅ YAML prettier 11 0 0 0 0.79s
✅ YAML v8r 11 0 0 12.22s
✅ YAML yamllint 11 0 0 0.55s

Notices

📣 MegaLinter 9.5.0 is out! Discover the new features and security recommendations in the release announcement. (Skip this info by defining SECURITY_SUGGESTIONS: false)

See detailed reports in MegaLinter artifacts

Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@9.5.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_GITLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,REPOSITORY_TRUFFLEHOG,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is graciously provided by OX Security
Show us your support by starring ⭐ the repository

@FlorianPfaff FlorianPfaff enabled auto-merge (squash) June 27, 2026 18:20
@FlorianPfaff FlorianPfaff merged commit 542f61a into main Jun 27, 2026
26 checks passed
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