Thanks to visit codestin.com
Credit goes to github.com

Skip to content

isnan should not raise TypeErrors (Trac #709) #1307

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

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 11 comments
Closed

isnan should not raise TypeErrors (Trac #709) #1307

numpy-gitbot opened this issue Oct 19, 2012 · 11 comments
Labels
00 - Bug component: numpy._core Priority: low Valid, but not for immediate attention

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/709 on 2008-03-20 by trac user cjw296, assigned to unknown.

I'm faily sure that:

numpy.isnan(datetime.datetime.now())

...should just return False and not raise an exception.

rationale: anything that is not nan should just return False, not raise TypeErrors.

@numpy-gitbot
Copy link
Author

@teoliphant wrote on 2008-04-03

Interesting suggestion, but this is a new feature. I'm moving it to 1.1

@numpy-gitbot
Copy link
Author

Milestone changed to 1.1 by @teoliphant on 2008-04-03

@numpy-gitbot
Copy link
Author

Milestone changed to Unscheduled by @cournape on 2009-03-02

@numpy-gitbot
Copy link
Author

@mwiebe wrote on 2011-03-23

This requires adding an object-array loop to the 'isnan' ufunc, which would then return False for anything that's not a float, and run the regular isnan on floats.

@antonywu
Copy link

In the meantime, what is the recommended solution, do we check for types before we throw things at numpy.isnan?
My current workaround is
import numpy as np def np_isnan(inputVal): try: return np.isnan(inputVal) except TypeError: return False

@charris
Copy link
Member

charris commented Jul 17, 2013

Example please.

@njsmith
Copy link
Member

njsmith commented Jul 17, 2013

Here's the rather elaborate workaround I use in patsy:
https://github.com/pydata/patsy/blob/master/patsy/util.py#L510

On Wed, Jul 17, 2013 at 3:53 AM, Charles Harris [email protected]:

Example please.


Reply to this email directly or view it on GitHubhttps://github.com//issues/1307#issuecomment-21089024
.

@charris
Copy link
Member

charris commented Feb 18, 2014

Still open and worth considering.

@mattip mattip added the Priority: low Valid, but not for immediate attention label May 7, 2019
@vitorbaptista
Copy link

vitorbaptista commented Apr 7, 2020

Although this seems to have been partially fixed on #14831, isnan still raises when called on an array with mixed column types. For example:

# This raises TypeError
np.isnan(
  np.array([
    [5],
    [np.datetime64('2010-01-01')]
  ])
)

# Both of these work fine
np.isnan(
  np.array([
    [np.datetime64('2010-01-01')]
  ])
)

np.isnan(
  np.array([
    [5]
  ])
)

I'm using numpy 1.18.2

@mattip
Copy link
Member

mattip commented Apr 8, 2020

By "mixed column types" you mean "when dtype is object", so the comment above is still true:

This requires adding an object-array loop to the 'isnan' ufunc, which would then return False for anything that's not a float, and run the regular isnan on floats.

This would start with adding a loop function to numpy/core/src/umath/loops.c.src, and then adding that function via TD(O, f='fancy_object_isnan') to numpy/core/code_generators/generate_umath.py which generates the code to call the loop for object arrays. Then add a few tests, adjust the test suite for any new failures, and add a release note.

@mattip
Copy link
Member

mattip commented Feb 24, 2021

Closing. If this is needed for your workflow please reopen or open a new issue.

@mattip mattip closed this as completed Feb 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
00 - Bug component: numpy._core Priority: low Valid, but not for immediate attention
Projects
None yet
Development

No branches or pull requests

6 participants