Skip to content
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

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

Closed
pont-us opened this issue Feb 10, 2023 · 1 comment · Fixed by #808
Closed
Assignees
Labels
bug Something isn't working

Comments

@pont-us
Copy link
Member

pont-us commented Feb 10, 2023

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.

@pont-us pont-us self-assigned this Feb 10, 2023
@pont-us pont-us added the bug Something isn't working label Feb 10, 2023
pont-us added a commit that referenced this issue Feb 10, 2023
pont-us added a commit that referenced this issue Feb 13, 2023
Before trying to remove the timezone from a label, check that the
relevant dimension is actually a datetime64.

Addresses #807.
pont-us added a commit that referenced this issue Nov 19, 2024
@pont-us
Copy link
Member Author

pont-us commented Nov 19, 2024

The warning type and message have now changed: it's now "UserWarning: no explicit representation of timezones available for np.datetime64". See numpy/numpy#23904 and numpy/numpy#24193 for details.

Also, xcube/xcube/core/_tile2.py, where the warning originates, has been renamed to tile.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant