Skip to content

BUG: np.timedelta64() and np.datetime64() do not raise any warning #31103

@riku-sakamoto

Description

@riku-sakamoto

Describe the issue:

generic unit in timedelta64 dtype is deprecated in the PR gh-29619, but np.timedelta64() do not raise DeprecationWarning when called.
This is same for np.datetime64(), which returns NaT without unit.

Current behavior:

np.timedelta64() # no warning, returns 0 timedelta with generic unit
np.datetime64() # no warning, returns NaT without unit

It might be good to set some specific unit such as "ns" as default unit.

I'd like to note @seberg 's comment here for reference.

Rethinking it, there some subtleties. I.e. np.array([np.timedelta64(3, "ns")], dtype="m") needs to keep working the way it currently does.
That is in principle not so hard, but in practice the path it currently takes is still np.dtype("m") -> unitless singleton -> type(uniteless singleton). But if np.dtype("m") there gives a warning, this conversion needs to happen later.
One thing I am not sure about is, if you were to change the default to ns for np.dtype("m") then some things might change behavior without a warning.

Reproduce the code example:

import numpy as np

np.timedelta64() # no warning, returns 0 timedelta with generic unit
np.datetime64() # no warning, returns NaT without unit

Error message:

Python and NumPy Versions:

2.5.0.dev0+git20260329.8568ed8
3.12.3 (main, Jul 12 2025, 11:14:50) [GCC 11.4.0]

Runtime Environment:

No response

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

This issue is reported and based on the discussion in gh-26919.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions