Skip to content

refactor: replace isProbability with inline range check in stats/base/dists/geometric/mgf#13386

Draft
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-stats-base-dists-geometric-2026-07-09
Draft

refactor: replace isProbability with inline range check in stats/base/dists/geometric/mgf#13386
Planeshifter wants to merge 1 commit into
developfrom
philipp/drift-stats-base-dists-geometric-2026-07-09

Conversation

@Planeshifter

Copy link
Copy Markdown
Member

Description

Normalizes the probability-range validation in @stdlib/stats/base/dists/geometric/mgf (both lib/main.js and lib/factory.js) from !isProbability( p ) to the inline form isnan( p ) || p < 0.0 || p > 1.0 used by every other JS member of the stats/base/dists/geometric namespace, and removes the now-unused @stdlib/math/base/assert/is-probability require from both files.

Mirrors the identical fix applied to stats/base/dists/bernoulli/mgf in merged PR #12292, which called out this package as the direct follow-up: "stats/base/dists/geometric/mgf carries the identical isProbability drift ... and is a clear follow-up candidate."

stats/base/dists/geometric/mgf

Replaces !isProbability( p ) with the inline isnan( p ) || p < 0.0 || p > 1.0 check in both lib/main.js and lib/factory.js, and drops the unused @stdlib/math/base/assert/is-probability import from each file. The inline form is what the other 13 non-ctor geometric siblings use (92.9% conformance); mgf was the sole outlier. isProbability( x ) is defined as !isnan( x ) && x >= 0.0 && x <= 1.0, so the two forms agree on NaN, ±Infinity, and all finite inputs; every boundary case exercised by test/test.mgf.js and test/test.factory.js (NaN, ±Infinity, -0.5, 2.0, 0.0, 1.0 for p) returns the same value as before. Verified by pre-/post-diff spot check from a Node REPL.

Related Issues

No.

Questions

No.

Other

Total diff: 2 files, 2 insertions, 4 deletions. Cross-run dedup against open PRs and the last 14 days of merged PRs targeting stats/base/dists/geometric confirms no overlap.

Sub-signal drift observed and deliberately not applied in this PR (logged for a future maintenance pass):

  • mgf/manifest.json uses 4-space JSON indentation vs the 2-space indentation used by the 13 other manifest.json files in the namespace and mandated by the root .editorconfig ([*.{json,json.txt}] indent_style = space, indent_size = 2). Whitespace-only; would muddy the semantic focus of this PR.
  • stdev package uses test/fixtures/python/ instead of the namespace-standard test/fixtures/julia/. Cascading — would require regenerating Julia fixtures and rewriting the tape loader in test/test.js and test/test.native.js; out of scope for a mechanical drift PR.

Checklist

AI Assistance

  • Yes
  • No

If you answered "yes" above, how did you use AI assistance?

  • Code generation (e.g., when writing an implementation or fixing a bug)
  • Test/benchmark generation
  • Documentation (including examples)
  • Research and understanding

Disclosure

This PR was authored by Claude Code via the cross-package drift-detection routine. Structural and semantic features were extracted from every member of stats/base/dists/geometric, the majority pattern was computed at a 75% conformance threshold, and three independent validation passes (semantic-review, cross-reference, structural-review) confirmed the single surviving correction was high-signal mechanical drift before any file was edited. The precedent set by merged PR #12292 (identical fix in the sibling bernoulli/mgf package) was cross-referenced and the same normalization applied here. A maintainer should audit and promote out of draft.


@stdlib-js/reviewers


Generated by Claude Code

…ase/dists/geometric/mgf`

Normalizes the probability-range validation in `@stdlib/stats/base/dists/geometric/mgf`
(both `lib/main.js` and `lib/factory.js`) from `!isProbability( p )` to the inline
form `isnan( p ) || p < 0.0 || p > 1.0` used by every other JS member of the
`stats/base/dists/geometric` namespace, and removes the now-unused
`@stdlib/math/base/assert/is-probability` require from both files.

`isProbability( x )` is defined as `!isnan( x ) && x >= 0.0 && x <= 1.0`, so the
two forms agree on NaN, +/-Infinity, and all finite inputs; observable behavior
is preserved (boundary cases `p = 0`, `p = 1`, `p = NaN`, `p = +/-Infinity`,
`p = -0.5`, `p = 2.0` all continue to return `NaN` or their prior finite value).

Namespace conformance: 13 of 14 non-`ctor` sibling packages use the inline
`isnan( p ) || p <op> 0.0 || p <op> 1.0` prologue (92.9%); `mgf` was the sole
outlier using the predicate form. Mirrors the identical normalization applied
to `stats/base/dists/bernoulli/mgf` in merged PR #12292, which flagged this
package as the natural follow-up.
@stdlib-bot stdlib-bot added the Statistics Issue or pull request related to statistical functionality. label Jul 9, 2026
@stdlib-bot

Copy link
Copy Markdown
Contributor

Coverage Report

Package Statements Branches Functions Lines
stats/base/dists/geometric/mgf $\\color{green}286/286$
$\\color{green}+100.00\\%$
$\\color{green}23/23$
$\\color{green}+100.00\\%$
$\\color{green}4/4$
$\\color{green}+100.00\\%$
$\\color{green}286/286$
$\\color{green}+100.00\\%$

The above coverage report was generated for the changes in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Statistics Issue or pull request related to statistical functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants