fix: correct overload param names, __array__ protocol, _wrap_result precedence, duplicate alias guard#720
Draft
henryiii wants to merge 2 commits into
Draft
fix: correct overload param names, __array__ protocol, _wrap_result precedence, duplicate alias guard#720henryiii wants to merge 2 commits into
henryiii wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #720 +/- ##
==========================================
+ Coverage 87.16% 87.22% +0.06%
==========================================
Files 96 96
Lines 11199 11221 +22
==========================================
+ Hits 9762 9788 +26
+ Misses 1437 1433 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
43 tasks
…ecedence, duplicate aliases Fix five classes of bugs in the object backend and overload definitions: 1. Overload parameter `ptau`/`pE`/`pe`/`pM`/`pm` → `pt` in tau/E/e/M/m temporal 4D overloads in both _methods.py and backends/object.py (the momentum alias for rho in polar-azimuthal coordinates is always `pt`). 2. `__array__` updated to accept `dtype` and `copy` per NumPy 2 protocol, so `np.asarray(v, dtype=...)` and `np.array(v, copy=False)` no longer raise TypeError; `copy=None` is accepted and ignored (output is always freshly allocated). 3. Operator-precedence bug in `VectorObject2D._wrap_result` and `VectorObject3D._wrap_result` where `and isinstance(...)` bound only to the right arm of `or`; the parentheses now match the intended logic. 4. `vector.obj(E=..., e=...)` and `vector.obj(M=..., m=...)` now raise TypeError instead of silently overwriting the first alias. 5. Minor docstring/error-message fixes: `LongitudinalObjectEta.elements` said "(``theta``)" → "(``eta``)"; twelve `VectorObject4D.from_*` docstrings said ``VectorObject3D``/`MomentumObject3D` → 4D; the `numpy.not_equal` ufunc branch error message said `'numpy.equal'`. Assisted-by: ClaudeCode:claude-sonnet-4-6
90631fc to
67a9e0a
Compare
Assisted-by: ClaudeCode:claude-opus-4.8
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.
🤖 AI text below 🤖
Summary
Five bug-fix groups in the object backend and overload definitions:
Typo'd overload parameter names (
ptau/pE/pe/pM/pm→pt): In the 4D overloads whose temporal coordinate istau/E/e/M/m, the transverse-momentum keyword was corrupted by a mechanical substitution. The correct momentum alias forrhowith polar azimuthal coordinates is alwayspt. Fixed in bothsrc/vector/_methods.pyandsrc/vector/backends/object.py.NumPy 2
__array__protocol: All six__array__methods inobject.pynow acceptdtype=Noneandcopy=Nonekeyword arguments. Previouslynp.asarray(v, dtype=np.float64)andnp.array(v, copy=False)raisedTypeError. Nowdtype=Nonereturns the array as-is (preserving subclass viaasanyarray), and any otherdtypeis forwarded tonumpy.asarray.Operator-precedence bug in
_wrap_result: InVectorObject2D._wrap_resultandVectorObject3D._wrap_resulttheisinstance(...)checks bound only to the right arm of theorinstead of the whole condition. Parentheses corrected to match the intended logic (latent bug — current dispatch maps do not trigger it).Duplicate temporal alias guard:
vector.obj(x=1, y=2, z=3, E=10, e=99)previously returnede=99silently (theebranch unconditionally overwrote thetset byE). Likewise forM+m. Both now raiseTypeError("duplicate coordinates ...").Docstring/error-message fixes:
LongitudinalObjectEta.elementsdocstring said "(theta)" → "(eta)"; twelveVectorObject4D.from_*docstrings saidVectorObject3D/MomentumObject3D→ 4D variants; thenumpy.not_equalufunc branch error message said'numpy.equal'.Test plan
uv run pytest tests/backends/test_object.py tests/test_methods.py -q— 8 passeduv run pytest --ignore=tests/test_notebooks.py -q— 813 passed, 3 skippedprek -a --quiet— all hooks passedtest_duplicate_temporal_aliases_raiseandtest_array_protocol_numpy2intests/backends/test_object.pyPart of #711
🤖 Generated with Claude Code