Skip to content

DOC: Incorrect description of in-place operations #28780

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
koyuki7w opened this issue Apr 20, 2025 · 2 comments
Open

DOC: Incorrect description of in-place operations #28780

koyuki7w opened this issue Apr 20, 2025 · 2 comments

Comments

@koyuki7w
Copy link
Contributor

Issue with current documentation:

https://numpy.org/devdocs/reference/generated/numpy.ndarray.__iadd__.html

In the documentation for in-place operations (__iadd__, __isub__, etc.), it states "Return self+=value." However, an in-place operation (self+=value) is a statement, not an expression, so it does not have a return value.

Idea or request for content:

The description should be same as self+=value, perform self+=value or something similar.

@mhvk
Copy link
Contributor

mhvk commented Apr 20, 2025

The docstring is indeed not very clear, but the __iadd__ operator does actually return an array; it is just that value is added in-place and then self is returned:

In [2]: a = np.arange(5.0)

In [3]: a.__iadd__(1)
Out[3]: array([1., 2., 3., 4., 5.])

In [4]: a
Out[4]: array([1., 2., 3., 4., 5.])

@koyuki7w
Copy link
Contributor Author

What I am pointing out is not whether __iadd__ returns a value, but whether it is appropriate to express the return value as self+=value. At least in the Python language, return self+=value is not syntactically correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants