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

Skip to content

DOC: update datetime documentation to explain that "NaT" also requires specific unit#31282

Merged
charris merged 4 commits intonumpy:mainfrom
riku-sakamoto:doc_update_for_datetime_nat
Apr 23, 2026
Merged

DOC: update datetime documentation to explain that "NaT" also requires specific unit#31282
charris merged 4 commits intonumpy:mainfrom
riku-sakamoto:doc_update_for_datetime_nat

Conversation

@riku-sakamoto
Copy link
Copy Markdown
Contributor

@riku-sakamoto riku-sakamoto commented Apr 20, 2026

PR summary

This is a follow-up PR based on the comment #31213 (comment)

Thank you for pointing it out! @lucascolley

AI Disclosure

I used ChatGPT to improve the English wording in this commit 3720a77 .


Previously, `datetime64` allowed `NaT` without specifying a time unit.
With the deprecation of generic units, `NaT` is now required to have an explicit time unit for consistency with other datetime and timedelta operations.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Be nice to break the long lines here and elsewhere. You need hard linebreaks.

Copy link
Copy Markdown
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 review! I've updated them accordingly.

[skip actions] [skip cirrus] [skip azp]
Comment thread doc/source/reference/arrays.datetime.rst Outdated
for consistency with other datetime and timedelta operations.

>>> np.datetime64("NAT")
DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, and will raise an error in the future. This includes implicit conversion of bare integers (e.g. `+ 1`).Please use a specific unit instead.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI suggests you can break this like so:

>>> np.datetime64("NAT")
DeprecationWarning: The 'generic' unit for NumPy timedelta is deprecated, ... Please use a specific unit instead.

I don't know if that works. We should probably fix the warning text.

Copy link
Copy Markdown
Contributor Author

@riku-sakamoto riku-sakamoto Apr 21, 2026

Choose a reason for hiding this comment

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

I left it as is because this is inside a code snippet.
When I tried to break the lines, the documentation ended up like below, so the line breaks appear as is.

Would you prefer line breaks even inside a code snippet, or should I keep it?

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

AI suggested shortening the output line using elipses ... for missing text. I don't know if it works, but maybe worth a try to find out. No, I wouldn't break the line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification.

I tried it locally, but I’m not sure if it improves the situation because it still doesn't fit one page width
Anyway, if you prefer, I am happy to push the changes.

image

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it works, we can always shorten the line more. I assume it worked? That is good to know. I'll put this in and you can make another PR if the improvement looks good. I think we could break it right after the elipses. It is just an example, if it occurs in the wild the user will see the whole thing.

Strictly speaking, it would be better to put some line breaks in the emitted warning message.

@ngoldbaum
Copy link
Copy Markdown
Member

Do the tests for the deprecation capture these cases?

@ngoldbaum ngoldbaum added this to the 2.5.0 Release milestone Apr 21, 2026
@riku-sakamoto
Copy link
Copy Markdown
Contributor Author

@ngoldbaum

Yes, I think so. The tests below capture the deprecation warnings

def test_raise_warning_for_NAT_construction(self):
self.assert_deprecated(lambda: np.datetime64('NaT'))
self.assert_deprecated(lambda: np.datetime64(None))

Copy link
Copy Markdown
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.

LGTM, thanks for following through on this @riku-sakamoto

@charris charris merged commit b728242 into numpy:main Apr 23, 2026
6 checks passed
@charris
Copy link
Copy Markdown
Member

charris commented Apr 23, 2026

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.

4 participants