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

Tile server: ensure timezone-naive time selector #602

Merged
merged 4 commits into from
Feb 4, 2022

Conversation

pont-us
Copy link
Member

@pont-us pont-us commented Feb 2, 2022

Fixes #555.

In tile._get_var_2d_array (used by new_color_mapped_image),
check for the possibility that the array uses datetime64 and the
indexer is timezone-aware. In this case, convert to a timezone-naive
indexer before performing the selection.

[Description of PR]

Checklist:

  • [ ] Add unit tests and/or doctests in docstrings (not needed)
  • [ ] Add docstrings and API docs for any new/modified user-facing classes and functions N/A
  • [ ] New/modified features documented in docs/source/* N/A
  • [ ] Changes documented in CHANGES.md N/A
  • AppVeyor CI passes
  • Test coverage remains or increases (target 100%)

Remember to close associated issues after merge!

Fixes #555.

In tile._get_var_2d_array (used by new_color_mapped_image),
check for the possibility that the array uses datetime64 and the
indexer is timezone-aware. In this case, covert to a timezone-naive
indexer before performing the selection.
Copy link
Contributor

@AliceBalfanz AliceBalfanz left a comment

Choose a reason for hiding this comment

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

Tested locally and works well :) Thanks for fixing!

Copy link
Member

@forman forman left a comment

Choose a reason for hiding this comment

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

  • The natural home of this fix should be xcube.core.tile.parse_non_spatial_labels()
  • I assume, the nature of the problem requires a more general solution. Hence, we need an understanding of the root cause and a general function that fixes the issue before timstamps are passed into xarray.Dataset/DataArray.sel().

Copy link
Contributor

@TonioF TonioF left a comment

Choose a reason for hiding this comment

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

I really would like a test for this. Also, I'd expect this issue to arise in more places than this. Did you check the other places?

xcube/core/tile.py Outdated Show resolved Hide resolved
@pont-us
Copy link
Member Author

pont-us commented Feb 3, 2022

I really would like a test for this.

OK, added.

@pont-us
Copy link
Member Author

pont-us commented Feb 3, 2022

Did you check the other places?

There seem to be fewer of them than I feared. I found time selection used in three other places in the xcube codebase:

  • core.select.select_temporal_subset
  • core.timeseries.get_time_series
  • cli.tile.tile

The last of these will be made safe by Norman's suggestion of moving the check to core.tile.parse_non_spatial_labels(), but the other two will require further work.

Move the call to xcube.core.tile._ensure_time_compatible from
_get_var_2d_array to parse_non_spatial_labels.
@pont-us
Copy link
Member Author

pont-us commented Feb 3, 2022

The natural home of this fix should be xcube.core.tile.parse_non_spatial_labels()

OK, moved.

@forman
Copy link
Member

forman commented Feb 4, 2022

but the other two will require further work.

Then let's just fix the server and enhance the issue #555 by your findings or create a new one.

@pont-us pont-us merged commit 5123085 into master Feb 4, 2022
@pont-us pont-us deleted the pont-555-tz-naive-index branch February 7, 2022 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Address xcube serve FutureWarning: timezone-naive DatetimeIndex with a timezone-aware datetime is deprecated
4 participants