Fix C3dMapper.__eq__() early return skipping remaining keys#384
Conversation
Closes pyomeca#383 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The meta_points dict contains numpy arrays directly (not parameter-style dicts), so the else branch needs to handle numpy array comparison to avoid "truth value of an empty array is ambiguous" ValueError. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address CodeRabbit review: use np.random.default_rng(42) instead of np.random.rand for deterministic test results. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
pariterre
left a comment
There was a problem hiding this comment.
@pariterre reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on @yasumorishima).
|
@yasumorishima |
|
Thank you for the review and approval! No rush at all — enjoy your vacation. I'm happy to help with anything when you're back. |
|
@yasumorishima Thanks for spoting this mistake again! |
|
Thanks @pariterre for merging this! Glad the eq() fix is in. Happy to help with ezc3d going forward. |
Summary
Closes #383
Fixes two early-return bugs in
C3dMapper.__eq__()that caused the comparison to stop after checking only the first key, instead of iterating through all keys.Changes
Bug 1: C3dMapper comparison (line 58)
Bug 2: numpy array comparison (line 62-67)
Bug 3:
__eq_param__numpy array handling (line 106-108)The fix to Bug 1 & 2 causes
meta_points(a dict containing numpy arrays likeresidualsandcamera_masks) to be properly reached and compared. The existingelsebranch in__eq_param__useddict1[key] != dict2[key], which raisesValueErrorfor numpy arrays. Fixed by adding annp.array_equalcheck for numpy array values.Tests
Added
test_eq()with 5 assertions:analogs(notpoints) makes them unequal — this was the core bug: previously returned Trueparameters(notheader) makes them unequal — same bug at top levelNote on
test_parse_and_rebuildfailuresSome existing
test_parse_and_rebuildandtest_parse_and_rebuild_datatests now fail for certain formats (BTS, Optotrak, Vicon, Label2). This is not caused by this PR — it is a pre-existing issue that was masked by the broken__eq__. The old__eq__returnedTrueafter comparing only the first key (points), so the write-read roundtrip data loss in other keys (meta_points,analogs, etc.) was never detected. Theheaderandparameterscomparisons continue to pass for all formats.This change is