-
Notifications
You must be signed in to change notification settings - Fork 52
Add isfinite
, isinf
, isscalar
, diagonal
, allclose
#213
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I like the approach with the ufunc
; we used it for np.mean or np.std before and I always thought that this should be expanded. Also, great tests!
See some comments below.
numpy-stubs/__init__.pyi
Outdated
@@ -390,6 +390,8 @@ class ndarray(Generic[_DType]): | |||
def __radd__(self, value: ndarray[_DType]) -> ndarray[_DType]: ... | |||
@overload | |||
def __radd__(self, value: _DType) -> ndarray[_DType]: ... | |||
@overload | |||
def __radd__(self, value: float) -> ndarray[_DType]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the return type should be float64?
def __radd__(self, value: float) -> ndarray[_DType]: ... | |
def __radd__(self, value: float) -> ndarray[float64]: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think that not necessarily... if _DType
is np.int64
, the return type will indeed be np.float64
, but this would not be true for complex types, for example.
Update: I've added complex64
and complex128
support, and I've incremented the test to check float + int and float + complex. This is returning _DType2
now.
# int, an int, and a callable, but there's no way to express | ||
# that. | ||
extobj: List[Union[int, Callable]] = ..., | ||
) -> Any: ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't love this Any return type. Is it possible to do an overload like we had before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I took this from NumPy stubs, I guess the return type from ufuncs is too broad, check this issue: numpy/numpy#17805
|
||
def test_sum_scalar_before() -> None: | ||
x = 273.15 + np.array([-0.1e2, -0.77e1]) | ||
assert isinstance(x, np.ndarray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert the type of the ndarray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done :)
…ove `isnan` support in NumPy stubs also add support for scalar + array fixes wearepal#209
47a5d0c
to
3fb733e
Compare
5b9a143
to
e4f26ee
Compare
and improve
isnan
support in NumPy stubs. Also add support for scalar + array.fixes #209