Re: Deprecation of `generic` unit in `timedelta64` dtype

Nathan via NumPy-Discussion <[email protected]> Sat, 7 Mar 2026 07:11:02 -0700
Newsgroups gmane.comp.python.numeric.general
Message-ID <CAJXewO=c-7zWh+3ue1dA5WL6o-XAA9tyg7DP5FRAHywnzNJSow@mail.gmail.com>
--===============9125926173510874669==
Content-Type: multipart/alternative; boundary="00000000000008dd63064c6fbe57"

--00000000000008dd63064c6fbe57
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Did you check whether this change impacts Pandas? They use numpy datetimes
and timedeltas.

If it does impact Pandas, I=E2=80=99d try to get the Pandas maintainers=E2=
=80=99 opinions.

On Sat, Mar 7, 2026 at 6:53=E2=80=AFAM riku-sakamoto via NumPy-Discussion <
[email protected]> wrote:

> 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 =3D 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=3D"m8")
>
> # `+ 1` is treated as adding 1 with generic timedelta
> np.array([1, 2], dtype=3D"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=3D"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]
>

--00000000000008dd63064c6fbe57
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"auto">Did you check whether this change impacts Pandas? They us=
e numpy datetimes and timedeltas.</div><div dir=3D"auto"><br></div><div dir=
=3D"auto">If it does impact Pandas, I=E2=80=99d try to get the Pandas maint=
ainers=E2=80=99 opinions.</div><div dir=3D"auto"><br><div class=3D"gmail_qu=
ote gmail_quote_container" dir=3D"auto"><div dir=3D"ltr" class=3D"gmail_att=
r">On Sat, Mar 7, 2026 at 6:53=E2=80=AFAM riku-sakamoto  via NumPy-Discussi=
on &lt;<a href=3D"mailto:[email protected]">numpy-discussion@pyth=
on.org</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"m=
argin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Dear NumPy de=
velopers,<br>
<br>
Hi all, I am Riku.<br>
I currently work on the PR #29619 ( <a href=3D"https://github.com/numpy/num=
py/pull/29619" rel=3D"noreferrer" target=3D"_blank">https://github.com/nump=
y/numpy/pull/29619</a> ), which deprecates `generic` unit in `timedelta64` =
dtype.<br>
This change is expected to have a large impact on the downstream libraries,=
 so I sent this email to notify it.<br>
<br>
Let me briefly summarize the motivation and changed behavior.<br>
<br>
Motivation:<br>
<br>
`generic` unit in `timedelta64` dtype is allowed to be operated with any ot=
her `timedelta64` dtype.<br>
So, comparison between several `timedelta64` dtypes including `generic` uni=
t becomes not transitive.<br>
It is reported in the issue #28287 ( <a href=3D"https://github.com/numpy/nu=
mpy/issues/28287" rel=3D"noreferrer" target=3D"_blank">https://github.com/n=
umpy/numpy/issues/28287</a> )<br>
<br>
```python<br>
x, y, z =3D np.timedelta64(1, &quot;ms&quot;), np.timedelta64(2), np.timede=
lta64(5, &quot;ns&quot;)<br>
print(x &lt; y &lt; z) # True, but x &lt; z is False<br>
```<br>
<br>
Changed behavior:<br>
<br>
After the deprecation, when using `generic` unit in `timedelta64` dtype, `D=
eprecationWarning` will be raised.<br>
<br>
Following operations will raise the warning:<br>
<br>
```python<br>
np.timedelta64(1)<br>
<br>
np.array([1, 2], dtype=3D&quot;m8&quot;)<br>
<br>
# `+ 1` is treated as adding 1 with generic timedelta<br>
np.array([1, 2], dtype=3D&quot;m8[s]&quot;) + 1<br>
```<br>
<br>
I want to note that `NaT` is also required to have specific unit. So, the f=
ollowing code will also raise the warning:<br>
<br>
```python<br>
np.array([&quot;NaT&quot;], dtype=3D&quot;m8&quot;)<br>
```<br>
<br>
I&#39;d appreciate it if you let me know when you have any questions or con=
cerns about this change.<br>
Any feedback is welcome.<br>
<br>
Best Regards,<br>
<br>
Riku<br>
_______________________________________________<br>
NumPy-Discussion mailing list -- <a href=3D"mailto:numpy-discussion@python.=
org" target=3D"_blank">[email protected]</a><br>
To unsubscribe send an email to <a href=3D"mailto:numpy-discussion-leave@py=
thon.org" target=3D"_blank">[email protected]</a><br>
<a href=3D"https://mail.python.org/mailman3//lists/numpy-discussion.python.=
org" rel=3D"noreferrer" target=3D"_blank">https://mail.python.org/mailman3/=
/lists/numpy-discussion.python.org</a><br>
Member address: <a href=3D"mailto:[email protected]" target=3D"_blank">=
[email protected]</a><br>
</blockquote></div></div>

--00000000000008dd63064c6fbe57--

--===============9125926173510874669==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
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]

--===============9125926173510874669==--