Skip to content
This repository was archived by the owner on Feb 17, 2021. It is now read-only.

Conversation

tadeu
Copy link

@tadeu tadeu commented Dec 22, 2020

and improve isnan support in NumPy stubs. Also add support for scalar + array.

fixes #209

Copy link
Member

@tmke8 tmke8 left a 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.

@overload
def __radd__(self, value: _DType) -> ndarray[_DType]: ...
@overload
def __radd__(self, value: float) -> ndarray[_DType]: ...
Copy link
Member

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?

Suggested change
def __radd__(self, value: float) -> ndarray[_DType]: ...
def __radd__(self, value: float) -> ndarray[float64]: ...

Copy link
Author

@tadeu tadeu Dec 22, 2020

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: ...
Copy link
Member

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?

Copy link
Author

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)
Copy link
Member

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?

Copy link
Author

@tadeu tadeu Dec 22, 2020

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
@tadeu tadeu force-pushed the add-isfinite-among-others branch from 47a5d0c to 3fb733e Compare December 22, 2020 18:01
@tadeu tadeu force-pushed the add-isfinite-among-others branch from 5b9a143 to e4f26ee Compare December 22, 2020 18:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Numpy has no method 'isfinite'

2 participants