Skip to content

ENH: Show unit information in repr for datetime64("NaT") #29396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 21, 2025

Conversation

riku-sakamoto
Copy link
Contributor

Overview

Details

Unlike timedelta objects, datetime64 does not display its unit in the repr output (see numpy#28496).
To maintain backward compatibility, this change adds unit information only when the datetime64 object has a NaT value.
@riku-sakamoto riku-sakamoto marked this pull request as ready for review July 19, 2025 08:53
Copy link
Member

@ngoldbaum ngoldbaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me. I think because this changes the repr it needs a release note, see doc/release/upcoming_changes/README.rst for more info about adding release note blurbs to PRs.


PyObject *meta = metastr_to_unicode(&scal->obmeta, 1);
if((scal->obval == NPY_DATETIME_NAT) && (meta != NULL)){
if (legacy_print_mode > 125) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess technically we could define a new numpy 2.3 legacy print mode as well. I don't know if it's worth the ceremony just for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment! Defining a new print mode feels like a bit too much as well, but I'm happy to give it a try if needed.

…aT")

Add a new release note for the change that shows time unit in the __repr__
output of datetime64("NaT"). See numpygh-29396.
@riku-sakamoto
Copy link
Contributor Author

riku-sakamoto commented Jul 21, 2025

Makes sense to me. I think because this changes the repr it needs a release note, see doc/release/upcoming_changes/README.rst for more info about adding release note blurbs to PRs.

@ngoldbaum
Thank you for the review! I've added a release note as suggested.

@ngoldbaum
Copy link
Member

Let's bring it in. If anyone reads this in the future because of downstream test failures please open an issue and we can reconsider adding a new legacy print mode.

@ngoldbaum ngoldbaum merged commit d2c0c10 into numpy:main Jul 21, 2025
76 checks passed
@ngoldbaum
Copy link
Member

Thanks @riku-sakamoto

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.

BUG: np.datetime64("nat", "ms") does not use unit in repr (unlike timedelta)
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy