astype with 'datetime64[us, UTC]' #958
Replies: 3 comments 2 replies
-
|
With respect to doing With respect to the second example, I don't think the expression |
Beta Was this translation helpful? Give feedback.
-
|
Hi all! 👋 Thanks for the detailed explanation. I totally understand the challenges with supporting all combinations of precision and timezone. I agree that UTC is by far the most common, so adding just datetime64[us, UTC] to the stubs sounds very pragmatic. It would definitely reduce the number of # type: ignore annotations users have to sprinkle in their code. From my side, I’d be happy to experiment with a small PR to include UTC in _typing.pyi. Even if it’s just a partial solution, it seems like it would fix a lot of real-world cases. Curious to hear if anyone has tried this already or has suggestions for how to structure the PR so it doesn’t bloat the stub definitions too much. |
Beta Was this translation helpful? Give feedback.
-
|
So it turns out that we do support the following as strings: "datetime64[s, UTC]",
"datetime64[ms, UTC]",
"datetime64[us, UTC]",
"datetime64[ns, UTC]",What's missing are the tests. They should be added to That won't handle the original request, which was to handle it via |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use
astypewithdatetime64[us, UTC].If I pass a string (as the docs):
I get:
I also tried:
numpy/numpy#16545 seems to imply that should work, but I thought I'd open a discussion here before an issue there.
Beta Was this translation helpful? Give feedback.
All reactions