Skip to content

fix: correct overload param names, __array__ protocol, _wrap_result precedence, duplicate alias guard#720

Draft
henryiii wants to merge 2 commits into
mainfrom
fix/object-backend-and-overloads
Draft

fix: correct overload param names, __array__ protocol, _wrap_result precedence, duplicate alias guard#720
henryiii wants to merge 2 commits into
mainfrom
fix/object-backend-and-overloads

Conversation

@henryiii

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

Summary

Five bug-fix groups in the object backend and overload definitions:

  • Typo'd overload parameter names (ptau/pE/pe/pM/pmpt): In the 4D overloads whose temporal coordinate is tau/E/e/M/m, the transverse-momentum keyword was corrupted by a mechanical substitution. The correct momentum alias for rho with polar azimuthal coordinates is always pt. Fixed in both src/vector/_methods.py and src/vector/backends/object.py.

  • NumPy 2 __array__ protocol: All six __array__ methods in object.py now accept dtype=None and copy=None keyword arguments. Previously np.asarray(v, dtype=np.float64) and np.array(v, copy=False) raised TypeError. Now dtype=None returns the array as-is (preserving subclass via asanyarray), and any other dtype is forwarded to numpy.asarray.

  • Operator-precedence bug in _wrap_result: In VectorObject2D._wrap_result and VectorObject3D._wrap_result the isinstance(...) checks bound only to the right arm of the or instead 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 returned e=99 silently (the e branch unconditionally overwrote the t set by E). Likewise for M+m. Both now raise TypeError("duplicate coordinates ...").

  • Docstring/error-message fixes: LongitudinalObjectEta.elements docstring said "(theta)" → "(eta)"; twelve VectorObject4D.from_* docstrings said VectorObject3D/MomentumObject3D → 4D variants; the numpy.not_equal ufunc branch error message said 'numpy.equal'.

Test plan

  • uv run pytest tests/backends/test_object.py tests/test_methods.py -q — 8 passed
  • uv run pytest --ignore=tests/test_notebooks.py -q — 813 passed, 3 skipped
  • prek -a --quiet — all hooks passed
  • New tests: test_duplicate_temporal_aliases_raise and test_array_protocol_numpy2 in tests/backends/test_object.py

Part of #711

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.22%. Comparing base (d9ef1db) to head (7c5490f).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…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
@henryiii henryiii force-pushed the fix/object-backend-and-overloads branch from 90631fc to 67a9e0a Compare June 16, 2026 04:04
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