Conversation
Audit of the whole library surfaced many bugs that the existing tests (which only exercised Pbox+Pbox) never caught. All fixes verified by running the code; adds tests/test_regression_v1.py to pin each one. Critical correctness: - pbox._arithmetic referenced undefined `other` -> Pbox+scalar/Interval (incl. N(0,1)+1) were broken - core.sum/mean: isinstance(x, [list,...]) raised TypeError - Interval.add/sub method 'p'/'o' missing return (returned None) - Interval.__ge__ was a copy-paste of __le__ (wrong results) - Interval.env([...]) isinstance list-literal bug - Pbox.exp/sqrt used wrong kwarg (function= vs func=) - beta() stray `args = list(args)` + invalid scipy support kwarg (also unbroke KN/KM) - what_I_know used `imp += pbox` (extends with values) and passed a list to imposition() - imposition() discarded p.imp() result; Pbox.imp used undefined `pbox` - min_mean off-by-one length mismatch - min_max_median built bounds from probabilities, not values High-severity logic: - always/never bare `False` (returned None) - Pbox.min/max error path called NotImplemented(...) as a function - logicaland/logicalor used builtin min/max on p-boxes; fixed all dependency methods and logicalor's wrong env() arity - core.sqrt checked "PBox" (typo); Interval.__pow__ UnboundLocalError on numpy exponents Cleanups: - __rsub__ interval branch, removed dead Pbox.mean method, uniform ignored steps, min_max_median_is_mode mean typo, removed broken t(), dropped debug prints / print->warn, removed dead pseudo-dunders, _check_steps no longer mutates operands, mixture raises instead of returning a string, invalid interpolation="outer", narrowed bare excepts, fixed backwards _check_div_by_zero guard Packaging / CI: - removed distutils setup.py (broke on 3.12) and stale MANIFEST; pyproject.toml is now authoritative (requires-python, classifiers, dev/docs extras) - CI: --cov=com -> --cov=pba, Python 3.10-3.13 matrix, install package - comprehensive .gitignore; updated release workflow V1 API: - added pba.__version__; exported Cbox/singh/min_mean/max_mean/ change_default_arithmetic_method; closed np/warnings namespace leak - added Interval.__hash__ (kept Logical-returning comparisons) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The Sphinx build had broken cross-references and an invalid directive, and 22 of 86 docstring examples were wrong (incorrect outputs, removed/renamed APIs, or implementation pseudo-code mislabelled as runnable examples). Code fix surfaced by the docs: - Interval.intersection used a containment test (straddles) instead of an overlap test, so Interval(0,1).intersection(Interval(0.5,1.5)) returned None instead of [0.5, 1] (the documented result). Now uses a proper overlap test; the list form checks max(lefts) <= min(rights). Docstring example fixes: - pba.pm -> pba.PM - never/xtimes examples had outputs contradicting the (correct) comparison logic; replaced with comparisons that demonstrate the documented results - whitespace: "Interval [0,1]" -> "Interval [0, 1]" to match repr - converted implementation pseudo-code and side-effecting plotting/repr examples (>>> self.*, pm_repr/lr_repr global mutation, Pbox.show) into illustrative code-blocks so they aren't run as doctests - marked the non-deterministic Interval.sample() example +SKIP Sphinx build (now warning-free): - fixed broken refs (pba.core.envelope, pba.pbox.Pbox.env, interpolation, lr_interval_repr) using :func:/:meth: roles - replaced invalid ".. example::" directive with ".. admonition:: Example" - replaced remote-image :scale: with :width: to avoid size warning - conf.py: release now read from package metadata (was v0.16.2); copyright year Doctest enforcement: - conftest.py injects pba/np/Interval/Pbox/Logical into the doctest namespace - pyproject pytest config: testpaths=[tests, pba], --doctest-modules, NORMALIZE_WHITESPACE + ELLIPSIS - testing.yml runs the full suite so examples can't silently drift again Co-Authored-By: Claude Opus 4.8 <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.
Overview
Takes the library from beta toward a trustworthy V1: fixes a large set of correctness bugs, cleans up packaging/CI, and makes the documentation accurate and self-verifying. Two commits:
A full read of every module surfaced many bugs that the previous test suite never caught (it only exercised
Pbox + Pbox). All fixes were verified by running the code; new tests pin each one. No public API was removed — only fixed/added.Why
Basic operations were broken in ways the tests didn't cover, e.g.
pba.N(0,1) + 1raisedTypeErrorandpba.what_I_know(minimum=0, maximum=10, mean=5)raised. The docs also drifted from the code (22 of 86 docstring examples were wrong, and the Sphinx build had broken references).Correctness fixes (verified)
Critical
Pboxarithmetic with scalars/Intervals was completely broken —_arithmeticreferenced an undefined variable (othervsb).pbox + 5,N(0,1) + 1,pbox + Intervalnow work.pba.sum/pba.meanraisedTypeError(isinstance(x, [list, ...])→ tuple).Interval.add/subwithmethod='p'/'o'returnedNone(missingreturn).Interval.__ge__was a copy-paste of__le__(wrong results).Interval.env([...])raised on list input;Pbox.exp/sqrtused the wrong kwarg.beta()(andKN/KM) raised;what_I_knowbuilt its imposition list wrong;imposition()discarded its result;min_meanhad a length mismatch;min_max_medianbuilt bounds from probabilities instead of values.High
always/neverreturnedNonefor mid-range values;Pbox.min/maxcalled theNotImplementedsingleton;logicaland/logicalorapplied builtinmin/maxto p-boxes;core.sqrthad a"PBox"typo;Interval.__pow__raised on numpy exponents.Other
Interval.intersectionused a containment test instead of overlap, soInterval(0,1).intersection(Interval(0.5,1.5))returnedNoneinstead of[0.5,1].__rsub__, removed a deadPbox.meanmethod,uniformignoringsteps, a mean-formula typo, a brokent()constructor, stray debug prints, dead pseudo-dunders, operand-mutating_check_steps,mixturereturning a string, an invalid interpolation method, and narrowed all bareexcept:clauses.Packaging / CI
setup.py(breaks on Python ≥3.12) and the staleMANIFEST;pyproject.tomlis now authoritative (requires-python, classifiers,dev/docsextras).--cov=com(nonexistent) →--cov=pba; added a Python 3.10–3.13 matrix and install the package itself..gitignore; updated the release workflow.API additions
pba.__version__; exportedCbox,singh,min_mean,max_mean,change_default_arithmetic_method; closed annp/warningsnamespace leak.Interval.__hash__(Intervals were unhashable because__eq__returns aLogical). Comparisons still returnLogicalby design.Documentation
pba.pm→PM, incorrectnever/xtimesoutputs,[0,1]→[0, 1]whitespace) and converted implementation/side-effecting pseudo-code into illustrative code blocks... example::directive, a remote-image:scale:warning;conf.pyversion now read from package metadata).conftest.pyinjects the common names,pyprojectenables--doctest-modules, and CI runs them so examples can't silently drift again.Reviewer notes
trapz,weibull) have questionable SciPy parameterizations that were left unchanged — they need domain validation rather than an obvious fix.tests/test_regression_v1.pyadds targeted regression coverage for each Tier-1/Tier-2 fix.Verification
pytest→ 64 passed (50 unit + 14 doctest items); Sphinx build succeeds with 0 warnings;python -m buildproduces a valid sdist/wheel.🤖 Generated with Claude Code
📚 Documentation preview 📚: https://readthedocs-preview--39.org.readthedocs.build/en/39/