[Python] Since timezone info is deprecated by numpy.datetime64 constructor, what's the right...

Discussão em 'Python' iniciado por Stack, Maio 12, 2025.

  1. Stack

    Stack Membro Participativo

    I have a timeseries with a large number of ISO 8601 datestrings and would like to convert to numpy.datetime64. But I get a warning:

    >>> import numpy as np
    >>> t=np.datetime64('2022-05-01T00:00:00-07:00')
    <stdin>:1: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future


    OK, so how do I avoid the warning? (Without giving up a significant performance factor)

    (Presumably the way to do this is convert to UTC and then create a datetime64 object, but the whole point of using datetime64 was that it worked directly on ISO 8601 strings very fast.)

    The documentation mentions this issue but doesn't suggest any solution:


    Deprecated since version 1.11.0: NumPy does not store timezone information. For backwards compatibility, datetime64 still parses timezone offsets, which it handles by converting to UTC±00:00 (Zulu time). This behaviour is deprecated and will raise an error in the future.
    ​

    Continue reading...

Compartilhe esta Página