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

The help of numpy.random.choice is not complete #2243

Closed
Vincent0706 opened this issue Jan 13, 2022 · 11 comments
Closed

The help of numpy.random.choice is not complete #2243

Vincent0706 opened this issue Jan 13, 2022 · 11 comments
Assignees
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@Vincent0706
Copy link

I found the help information of numpy.random.choice is not complete. It only have the function declaration.

image

@erictraut
Copy link
Contributor

I presume that you're looking for a docstring or other documentation?

The type information and docstrings come from numpy itself. If you right-click on choice and select "Go To Declaration", you'll see which file this information comes from. In the latest release of numpy, choice is declared in a type stub file numpy/random/mtrand.pyi. Unfortunately, it doesn't include any docstrings, so pylance has nothing to display. You may want to file a bug (or better yet, a PR) in the numpy github repo.

@Vincent0706
Copy link
Author

Vincent0706 commented Jan 13, 2022

Thank you, I have reported to numpy.

@bashtage
Copy link

Putting type information only in pyi files is standard. docstrings are not incorporated in these files generally. Other IDEs, e.g., PyCharm, can seamlessly incorporate pyi information with standard docstrings. I don't expect NumPy, or many other projects that have compiled code and use pti for typing, will move their docstrings away from the code into type stub files.

Related to numpy/numpy#20809

@Vincent0706
Copy link
Author

numpy/numpy#20809 (comment)
According to this, it seems to be pylance's or python-extention's problem.

@BvB93
Copy link

BvB93 commented Jan 13, 2022

numpy/numpy#20809 (comment)
According to this, it seems to be pylance's or python-extention's problem.

Following up on this comment: the issue seems to be limited to functions that are purely C- or Cython-based, lacking any wrapper of some sort written in pure-python.

@bashtage
Copy link

@BvB93 Do the examples of functions with python wrappers have docstrings and typing information together. or is the docstring in the .py file and the typing in a .pyi?

@Vincent0706
Copy link
Author

I don't know what is python wrappers. But in numpy 1.20.3 version, I right-click on choice and select "Go To Declaration". I can't found any docstrings or typing information.

image

@BvB93
Copy link

BvB93 commented Jan 13, 2022

@BvB93 Do the examples of functions with python wrappers have docstrings and typing information together. or is the docstring in the .py file and the typing in a .pyi?

The docstrings and annotations are always split between .py/.pyx and .pyi files.
Just to give a few more examples from my previous point:

Shows docstrings

Does not show docstrings

@erictraut
Copy link
Contributor

Pylance will find and display docstrings for functions and classed declared in ".pyi" files if it can find the same symbol in a corresponding ".py" file. In the case of np.random.choice, there is no corresponding ".py" file though. When functions are implemented in a language other than Python, there is no static way to access the docstring if it's not in the ".pyi" file. As such, it is recommended that the ".pyi" include the docstring. Refer to this guidance for more details.

@judej judej added the needs investigation Could be an issue - needs investigation label Jan 13, 2022
@github-actions github-actions bot removed the triage label Jan 13, 2022
@heejaechang heejaechang added fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed needs investigation Could be an issue - needs investigation labels Jan 14, 2022
@heejaechang heejaechang self-assigned this Jan 19, 2022
@bschnurr
Copy link
Member

This issue has been fixed in version 2022.1.3, which we've just released. You can find the changelog here: CHANGELOG.md

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

7 participants