numpy / numpy/numpy

BUG: Inconsistent handling of `np.nan` in `np.timedelta64` arrays

Open
#30,959 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the issue:

np.nan is not allowed when creating np.timedelta64 arrays, but np.full allows it.
Would it be better to allow np.nan in np.timedelta64 arrays?

Reproduce the code example:
import numpy as np

# This code is allowed
np.full((3, 3), np.nan, dtype="m8[s]")

# This raise ValueError
np.array([np.nan], dtype="m8[s]")
Error message:

Python and NumPy Versions:

2.5.0.dev0+git20260306.34bb046

Runtime Environment:

No response

How does this issue affect you or how did you find it:

Through investigation of the effect of #29619 , I've found this issue.

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

No source file or test is named. Start by reproducing the two examples and reviewing the investigation linked to #29619, then trace the np.timedelta64 and np.full conversion paths. Done means the intended np.nan behavior is decided and covered consistently by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.