Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH,WIP: Adding "casting" keyword to close and equal functions in numeric (fix #17136) #18950

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

Open
wants to merge 13 commits into
base: main
Choose a base branch
Loading
from

Conversation

lschwetlick
Copy link
Contributor

@lschwetlick lschwetlick commented May 9, 2021

As discussed in #17136 , the functions

  • isclose
  • allclose
  • array_equal
  • array_equiv

currently implicitly cast between data types without warning or error. Eg.:

np.isclose([1],[True])
> True

In this PR we add the "casting" keyword to specify at which level inputs should be cast in the comparison. For example:

np.isclose([1],[True], casting="unsafe")
> True
np.isclose([1],[True], casting="safe")
> TypeError...

@charris
Copy link
Member

charris commented May 11, 2021

@lschwetlick Lint is unhappy.

./numpy/core/numeric.py:2348:32: E225 missing whitespace around operator
./numpy/core/numeric.py:2455:32: E225 missing whitespace around operator
./numpy/core/numeric.py:2519:31: E225 missing whitespace around operator
3       E225 missing whitespace around operator

@lschwetlick
Copy link
Contributor Author

lschwetlick commented May 12, 2021

Yup, thanks for putting it on my radar :) We are still discussing other stuff that needs doing in this Issue thread #17136 . I'll work on it in the next few days!

Copy link
Member

@BvB93 BvB93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got a couple of comments that apply to all functions changed within this PR.

Secondly, the annotation of the respective functions will have to be updated in the stub file: https://github.com/numpy/numpy/blob/main/numpy/core/numeric.pyi

By the looks of it something like this should suffice:

from numpy import _Casting  # A string-`Literal` containing all valid casting kinds

def isclose(
    a: ArrayLike,
    b: ArrayLike,
    rtol: float = ...,
    atol: float = ...,
    equal_nan: bool = ...,
    casting: _Casting = ...,  # The new keyword
) -> Any: ...

numpy/core/numeric.py Outdated Show resolved Hide resolved
numpy/core/numeric.py Outdated Show resolved Hide resolved
numpy/core/numeric.py Outdated Show resolved Hide resolved
@BvB93 BvB93 linked an issue May 17, 2021 that may be closed by this pull request
@BvB93 BvB93 changed the title [WiP] Adding "casting" keyword to close and equal functions in numeric (fix #17136) ENH,WIP: Adding "casting" keyword to close and equal functions in numeric (fix #17136) May 17, 2021
@BvB93 BvB93 added the 56 - Needs Release Note. Needs an entry in doc/release/upcoming_changes label May 17, 2021
lschwetlick and others added 9 commits July 17, 2021 10:59
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
Co-authored-by: Bas van Beek <43369155+BvB93@users.noreply.github.com>
@lschwetlick
Copy link
Contributor Author

Sorry for the delay working on this. Somehow I the discussion we were having in #17136 of whether we should go ahead with this was never really resolved. I incorporated the suggestions of @BvB93 now.
ping @rgommers and @ijoseph

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Awaiting a decision
Development

Successfully merging this pull request may close these issues.

allclose should at least warn about type mismatches
4 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.