Thanks to visit codestin.com
Credit goes to github.com

Skip to content

BUG: avoid a deprecation warning from numpy 2.5 (calling datetime64('NaT') without a unit is deprecated)#31554

Merged
story645 merged 2 commits intomatplotlib:mainfrom
neutrinoceros:compat/numpy2.5/datetime64-unit
Apr 23, 2026
Merged

BUG: avoid a deprecation warning from numpy 2.5 (calling datetime64('NaT') without a unit is deprecated)#31554
story645 merged 2 commits intomatplotlib:mainfrom
neutrinoceros:compat/numpy2.5/datetime64-unit

Conversation

@neutrinoceros
Copy link
Copy Markdown
Contributor

PR summary

xref numpy/numpy#31213
xref numpy/numpy#31282

AI Disclosure

no AI was used at any point.

PR checklist

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

failures seem unrelated.
I'm uncertain if a new test is needed here. If the line is already covered (and I don't know that it is) you'd hit the deprecation warning sooner or later, and matplotlib is tested against numpy dev.

@rcomer
Copy link
Copy Markdown
Member

rcomer commented Apr 23, 2026

If the line is already covered (and I don't know that it is) you'd hit the deprecation warning sooner or later, and matplotlib is tested against numpy dev.

We have a regular Saturday task for testing against upstream nightly builds, so the laziest way to find out is to wait a couple of days.

@neutrinoceros
Copy link
Copy Markdown
Contributor Author

lazy way it goes 😄
but ftr, we discovered this by testing astropy against matplotlib + numpy nightlies, so I know this line is affected but the deprecation warning.

@neutrinoceros neutrinoceros marked this pull request as ready for review April 23, 2026 13:20
@jklymak
Copy link
Copy Markdown
Member

jklymak commented Apr 23, 2026

I'm pretty wary about this change. Does NAT[s] return the same thing as NAT[ns] when converted to int64? I think it is a bit strange that numpy is wanting NaT to have a unit.

@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 23, 2026

@jklymak sorry I accidentally edited your commit. - Reverted to the original.

Does NAT[s] return the same thing as NAT[ns] when converted to int64?

It currently does in 2.4.4. The question whether that's guaranteed behavior.

In [7]: np.timedelta64("NaT", 'ns') == np.timedelta64("NaT", "s")
Out[7]: np.False_

In [9]: np.timedelta64("NaT", 'ns').astype(np.int64) == np.timedelta64("NaT", "s").astype(np.int64)
Out[9]: np.True_
Otherwise, we'd have to create the right timedelta NaT.

Semi-related: We do this whole song-and-dance to create a boolean array marking the NaT entries in an datetime64 array. Isn't there a more straight forward solution for that?

Comment thread lib/matplotlib/dates.py Outdated
Co-authored-by: Tim Hoffmann <[email protected]>
@timhoffm
Copy link
Copy Markdown
Member

timhoffm commented Apr 23, 2026

Code path is coverd by test_date2num_NaT and test_date2num_NaT_scalar, so the fix is verified through CI.

@QuLogic Let's include this into 3.11 so that users won't run into the deprecation when numpy 2.5 comes out.

@timhoffm timhoffm added this to the v3.11.0 milestone Apr 23, 2026
@story645 story645 merged commit cf3aacf into matplotlib:main Apr 23, 2026
40 of 41 checks passed
@neutrinoceros neutrinoceros deleted the compat/numpy2.5/datetime64-unit branch April 23, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants