-
-
Notifications
You must be signed in to change notification settings - Fork 10.8k
np.searchsorted documentation and typing missing that single values are allowed #19160
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
Comments
@BvB93 That's good news on the typing. But the docs should be fixed as well. |
I agree, yes. A documentation fix is currently up at #19165. |
The typing issue can cause mypy errors as a result. This is a regression from earlier numpy versions. E.g.: index = np.searchsorted(foo, 2)
baz = bar[:index]
|
That would make sense, as numpy versions prior to 1.20 didn't contain any type annotations (i.e. As for the provided example, I'm afraid that the issue you're looking at is mypy being overly strict (xref python/mypy#2410). In contrast, |
Documentation
The documentation (and associated typing in the
pyi
files) fornp.searchsorted
is missing that you can pass a single argument. and get a single integer as the return type.https://numpy.org/doc/stable/reference/generated/numpy.searchsorted.html
Example code that illustrates this:
Result of running this is:
If I uncomment the
reveal_type
lines, the types ofa
ands
are bothnp.ndarray
.So the docs should be updated to reflect that you can pass a single value, and, as a result a single integer is returned. In addition, the typing signature should be fixed as well.
The text was updated successfully, but these errors were encountered: