Deprecation of `generic` unit in `timedelta64` dtype

riku-sakamoto via NumPy-Discussion <[email protected]> Sat, 07 Mar 2026 07:52:32 -0000
Newsgroups gmane.comp.python.numeric.general
Message-ID <[email protected]>
Dear NumPy developers,

Hi all, I am Riku.
I currently work on the PR #29619 ( https://github.com/numpy/numpy/pull/29619 ), which deprecates `generic` unit in `timedelta64` dtype.
This change is expected to have a large impact on the downstream libraries, so I sent this email to notify it.

Let me briefly summarize the motivation and changed behavior.

Motivation:

`generic` unit in `timedelta64` dtype is allowed to be operated with any other `timedelta64` dtype.
So, comparison between several `timedelta64` dtypes including `generic` unit becomes not transitive.
It is reported in the issue #28287 ( https://github.com/numpy/numpy/issues/28287 )

```python
x, y, z = np.timedelta64(1, "ms"), np.timedelta64(2), np.timedelta64(5, "ns")
print(x < y < z) # True, but x < z is False
```

Changed behavior:

After the deprecation, when using `generic` unit in `timedelta64` dtype, `DeprecationWarning` will be raised.

Following operations will raise the warning:

```python
np.timedelta64(1)

np.array([1, 2], dtype="m8")

# `+ 1` is treated as adding 1 with generic timedelta
np.array([1, 2], dtype="m8[s]") + 1
```

I want to note that `NaT` is also required to have specific unit. So, the following code will also raise the warning:

```python
np.array(["NaT"], dtype="m8")
```

I'd appreciate it if you let me know when you have any questions or concerns about this change.
Any feedback is welcome.

Best Regards,

Riku
_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/numpy-discussion.python.org
Member address: [email protected]