numpy / numpy/numpy

BUG: np.isnat fails on non-datetime

Open
#23,582 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
32.8k
Forks
12.8k
Avg merge
1d 7h
Merged PRs (30d)
197

Description

The function np.isnat asks a very specific question, which is what it says on the tin "is the argument the nan-marker for datetime/timedelta?"

There are situations -- especially in trying to write library code that survives a lot of user inputs (or tests for that) -- where it's necessary or at least desirable to handle NaT specifically.

However the function unfortunately is way less useful than it could be, because it only works for datetime/timedelta:

TypeError: ufunc 'isnat' is only defined for np.datetime64 and np.timedelta64

so now, to use it somewhere (that's not in a hyperspecific chain of branches), I have to write

isinstance(x, (np.datetime64, np.timedelta64)) and np.isnat(x)

to achieve what np.isnat(x) could be doing in the first place.

Why not make this function simply return False instead of TypeError in that case?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the np.isnat entry point and examining how it handles non-datetime and non-timedelta inputs. Done means that those inputs return False instead of raising the reported TypeError, while existing datetime and timedelta behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.