-
Notifications
You must be signed in to change notification settings - Fork 769
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
Missing info for numpy #150
Comments
Much of numpy is compiled. We currently don't have a scraper that will create type stubs for compiled modules. Therefore, for now, a fix would be for numpy to ship stubs / annotations to describe their code, which I believe that they have merged. I'd be curious if this works better in numpy 1.19 (which I think has the stubs, but I'm unsure). |
Thanks for the tip @jakebailey ! I've upgraded to numpy 1.19.1 but unfortunately, I'm still encountering the above. |
I'm going to retitle this and use this to deduplicate numpy issues. |
Note: there's already been a PR merged into numpy (numpy/numpy#16515) that adds type stubs (these used to be in a separate repo), but the commit isn't in a release yet. So, this should be working better soon. |
There are other packages with this same problem (i.e. Pysam). Is it possible to add a setting to disable |
Does this issue also including the problem that doc strings are not displayed for some numpy functions such as |
Yes. These functions are from compiled modules; there's no source code we can read to obtain them. Some of these functions are showing up only because Numpy's next release is supposed to include stubs, which will make these functions known, however the docstrings are still only going to be in the compiled module where we can't access them without actually running Python and live importing the module to extract it. |
Looks like the stubs are coming in NumPy 1.20. It's not clear to me if this will help with auto-completion in situations such as the following in VS Code with PyLance: def test() -> np.ndarray:
return np.arange(5)
x = test()
# x. <tab> doesn't give me any ndarray completions and the hover-text for test() says it returns Any
# n.b. it doesn't help to annotate x: np.ndarray either. When I select
(?) I think this NumPy issue is especially relevant: ENH: Add annotations to |
We were hoping that the new numpy stubs would help immensely (as opposed to the "actually run it and see" method), but I know that a lot of the current numpy stubs right now are just Hopefully they don't go and release with incomplete stubs... |
Are you on at least numpy 1.20? That function is defined in their stubs and should appear, but may not on older versions of numpy without type info. |
thanks. upgrading to 1.20 version helped! |
Hi @jakebailey , I am new to vscode, and also encounter this issue. I understand that these compiled packages are hard to get the type info. But I notice that Pycharm can detect those types accurately, any idea how they make this? Thanks in advance! |
Not sure if this will be of any help, but the next 1.21 release should improve many of the annotations. |
Without reading their implementation, either by running the library to obtain info at runtime (scraping), or by hardcoding, both of which we do not do. We have prescraped stubs for some info, but largely rely on numpy itself to provide types.
Hm, I could have sworn this was to be there for 1.20.3, but maybe only a small subset was backported. |
These were two different, albeit related, issues:
The first issue was indeed fixed in 1.20.3, the second one is scheduled for 1.21. |
new numpy release with improved annotations https://github.com/numpy/numpy/releases/tag/v1.21.0rc1 |
In my case, if a numpy array, say "A", is not created with "A=np.zeros()" or "A=np.empy()", then Pylance can't recognize the property "A.shape", e.g., if "A" is created with "np.frombuffer()". |
If you select "Go to Declaration" for def frombuffer(buffer, dtype=..., count=..., offset=..., *, like=...): ... So this is bug (an omission) within the numpy library. You can report the bug (or better yet, submit a PR) in the numpy repo. |
@erictraut Thanks. I see now. |
FYI, annotations for |
original issue fixed. any further missing numpy type annotations should be logged there. |
Environment data
Expected behaviour
When I hover over np.ndarray I expected to see
(class) ndarray
Actual behaviour
When I hover over np.ndarray it says
(import) ndarray: Unknown
Code Snippet / Additional information
numpy 1.18.1
The text was updated successfully, but these errors were encountered: