Skip to content
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

DOC: Explicitly mention a function's aliases in the documentation #19717

Closed
Darylgolden opened this issue Aug 20, 2021 · 4 comments · Fixed by #23302
Closed

DOC: Explicitly mention a function's aliases in the documentation #19717

Darylgolden opened this issue Aug 20, 2021 · 4 comments · Fixed by #23302

Comments

@Darylgolden
Copy link

Darylgolden commented Aug 20, 2021

I was trying to find the round function in the documentation, but could not find it, making me falsely believe that it was deprecated. It was only after more research that I found that it was defined as an alias. I think this should be explicitly mentioned in the documentation (and for all other functions which have aliases too) to reduce confusion.

@phetdam
Copy link
Contributor

phetdam commented Aug 22, 2021

Yes, depending on the version of NumPy np.round points to np.round_ or np.around. Commonly np.round_ also points to np.around. The current docs don't document np.round but the docs for np.round_ note that np.around is equivalent.

I am not sure about this, but the aliased NumPy functions may be the way they are for historical reasons, i.e. to not break code written using older versions of NumPy. Newer code should probably use the new functions directly.

@Darylgolden
Copy link
Author

Even the np.around documentation uses np.round. This is rather confusing and I'm not sure what the "best practice" is.

@phetdam
Copy link
Contributor

phetdam commented Aug 23, 2021

Not exactly. I jumped through the code of the current main and np.round_ calls np.around while np.around dispatches to ndarray.round. I'd say this is probably because ndarray.round, a method_descriptor, provides/calls into a C implementation and all these top-level functions just wrap it. Not sure why all the aliasing exists however; maybe one of the core members knows. I checked some docs for NumPy 1.6 and these functions still existed then so my supposition of "historical reasons" is out the window.

I guess that "best practice" would be to use whatever is more natural then, so using np.round vs. np.around shouldn't be a point of stress, but on second thought there is a situational aspect to it. Let's consider the differences between np.round_/np.around and ndarray.round. The former functions have the out argument that allows us to write the result into an existing ndarray, which is useful when you don't want to create a new ndarray for whatever reason. E.g.

ar = np.array([1, 2, 2.32, 1.111])
ar = np.round(ar, out=ar)

This performs the rounding in-place on ar. However, ar.round() will allocate a new ndarray with the same results.

@aparnabushan
Copy link
Contributor

I am working on this issue as part of pycon india conference.

InessaPawson added a commit to InessaPawson/numpy that referenced this issue Jun 26, 2022
Co-authored-by: Mukulika Pahari <mukulikapahari@gmail.com>, Aparna Bushan <aparna.bushan@auto-grid.com>
@InessaPawson InessaPawson changed the title Explicitly mention a function's aliases in the documentation DOC: Explicitly mention a function's aliases in the documentation Oct 31, 2022
rgommers added a commit to rgommers/numpy that referenced this issue Feb 28, 2023
The function is more commonly called `round`, both in the array API
standard and in other array libraries (e.g., PyTorch has `round` but not
around). Plus we have `ndarray.round`.
`around` is heavily used, so keep it as an alias - but prefer `round`.
For both this switch and for keeping the alias, xref numpygh-13877.

Closes numpygh-19717
rgommers added a commit to rgommers/numpy that referenced this issue Feb 28, 2023
The function is more commonly called `round`, both in the array API
standard and in other array libraries (e.g., PyTorch has `round` but not
around). Plus we have `ndarray.round`.
`around` is heavily used, so keep it as an alias - but prefer `round`.
For both this switch and for keeping the alias, xref numpygh-13877.

Closes numpygh-19717
rgommers added a commit to rgommers/numpy that referenced this issue Mar 1, 2023
The function is more commonly called `round`, both in the array API
standard and in other array libraries (e.g., PyTorch has `round` but not
around). Plus we have `ndarray.round`.
`around` is heavily used, so keep it as an alias - but prefer `round`.
For both this switch and for keeping the alias, xref numpygh-13877.

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

Successfully merging a pull request may close this issue.

3 participants