xcube-dev/xcube

Avoid numpy "parsing timezone aware datetimes is deprecated" warning in tile server

Opened this issue · 0 comments

Describe the bug

The following warning appears when the server is serving tiles to the viewer:

xcube/xcube/core/_tile2.py:659: DeprecationWarning: parsing timezone aware datetimes is deprecated; this will raise an error in the future

To Reproduce

Start an xcube viewer and server, including the --warnings flag to the server to display warnings. Perform some typical user activities in the viewer (pan, zoom, etc.). The warning will appear in the server log output.

Expected behavior

It is expected that this warning will not appear.

Additional context

While this bug currently has no consequences beyond the warning, xcube does not set an upper limit on the numpy version in its dependencies. Therefore any future numpy release may upgrade this warning to an error and break all xcube server installs from that moment onward.

The error occurs because the viewer requests a tile with a timezone-aware datestamp (Z suffix) -- see #605 for more on this. While this might be considered incorrect in cases where the time dimension of the data is timezone-naive, the server should in any case be able to handle both timezone-naive and timezone-aware datestamps.

The warning can be reproduced in isolation like this:

import numpy as np
np.array('2018-12-31T00:00:00Z').astype('datetime64[ns]')

Probably the most sensible fix is to do a specific check in the _tile2 module for this particular case (datetime64 target type, timezone-aware string), convert to UTC, and force to naive -- in effect reproducing the old behaviour of numpy.