Skip to content

[cppyy] fix iadd pythonization for np/array buffers #18999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aaronj0
Copy link
Contributor

@aaronj0 aaronj0 commented Jun 9, 2025

Backport of wlav/CPyCppyy#51
Fixes #18768

Currently, the iadd implementation for std::vector in Pythonize.cxx works perfectly with Python lists and iterables for which we have an ItemGetter. But the code path for numpy/array buffers do not. The difference between x+=y and x.__iadd__(y) leads to unintuitive behaviour: if the intent is to obtain the resulting iterator when calling insert, the user can do d.insert(d.end(), a) which makes more sense than expecting it from d+=a. When the user does call d+=a, since __iadd__ is overriden, operation does not end with the call to VectorIAdd which should just return the iterator, and reflect the change by insertion on d. Instead, it ends with d = d.__iadd__(a) which reassigns d to the returned iterator, losing the vector in the process. This PR fixes this by returning self in our pythonization.

@aaronj0 aaronj0 self-assigned this Jun 9, 2025
Copy link

github-actions bot commented Jun 9, 2025

Test Results

    19 files      19 suites   3d 7h 0m 28s ⏱️
 2 802 tests  2 802 ✅ 0 💤 0 ❌
51 744 runs  51 744 ✅ 0 💤 0 ❌

Results for commit 4d4db8e.

@aaronj0 aaronj0 requested a review from guitargeek June 9, 2025 20:40
@dpiparo
Copy link
Member

dpiparo commented Jun 10, 2025

Thanks for these changes. Can we add a (some) test(s)?

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.

Regression in i-adding array.array to std::vector in PyROOT
2 participants