From bb2e7914712ca5913d9ad54e4b3242242f98daa0 Mon Sep 17 00:00:00 2001 From: Ricardo Garcia Silva Date: Wed, 13 Dec 2023 10:52:15 +0000 Subject: [PATCH] Prepare code and CI for Python 3.8 (#1399) * Refactored get_collection_coverage tests Using pytest's parametrize mark. This makes it easier to isolate test cases in order to fix the errors that are showing up when running under Python3.8 * Refactor tests from test_api.py that were failing under Python 3.8 * Fix flake8 issues * Add Python 3.8 to the CI matrix * Replaced pandas usage with numpy for datetime * Reverted tests back to non-parametrized form * Dropped Python 3.7 from main github CI workflow --------- Co-authored-by: Ricardo Garcia Silva --- .github/workflows/main.yml | 4 ++-- pygeoapi/provider/xarray_edr.py | 32 ++++++++++++++++++++------------ tests/pygeoapi-test-config.yml | 2 -- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 047a172..9575a7b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -20,7 +20,7 @@ jobs: - name: Setup Python uses: actions/setup-python@v1 with: - python-version: 3.7 + python-version: 3.8 architecture: x64 - name: Checkout pygeoapi uses: actions/checkout@master @@ -39,7 +39,7 @@ jobs: strategy: matrix: include: - - python-version: 3.7 + - python-version: 3.8 env: PYGEOAPI_CONFIG: "$(pwd)/pygeoapi-config.yml" diff --git a/pygeoapi/provider/xarray_edr.py b/pygeoapi/provider/xarray_edr.py index 0d746e3..f3c3e1a 100644 --- a/pygeoapi/provider/xarray_edr.py +++ b/pygeoapi/provider/xarray_edr.py @@ -122,17 +122,25 @@ class XarrayEDRProvider(BaseEDRProvider, XarrayProvider): data = self._data[[*select_properties]] else: data = self._data - if (datetime_ is not None and - isinstance(query_params[self.time_field], slice)): # noqa - # separate query into spatial and temporal components - LOGGER.debug('Separating temporal query') - time_query = {self.time_field: - query_params[self.time_field]} - remaining_query = {key: val for key, - val in query_params.items() - if key != self.time_field} - data = data.sel(time_query).sel(remaining_query, - method='nearest') + + if self.time_field in query_params: + remaining_query = { + key: val for key, val in query_params.items() + if key != self.time_field + } + if isinstance(query_params[self.time_field], slice): + time_query = { + self.time_field: query_params[self.time_field] + } + else: + time_query = { + self.time_field: ( + data[self.time_field].dt.date == + query_params[self.time_field] + ) + } + data = data.sel( + time_query).sel(remaining_query, method='nearest') else: data = data.sel(query_params, method='nearest') except KeyError: @@ -259,7 +267,7 @@ class XarrayEDRProvider(BaseEDRProvider, XarrayProvider): LOGGER.debug('Reversing slicing from high to low') return slice(end, begin) else: - return datetime_ + return np.datetime64(datetime_) def _get_time_range(self, data): """ diff --git a/tests/pygeoapi-test-config.yml b/tests/pygeoapi-test-config.yml index 18017aa..2cd2579 100644 --- a/tests/pygeoapi-test-config.yml +++ b/tests/pygeoapi-test-config.yml @@ -282,8 +282,6 @@ resources: - type: coverage name: rasterio data: tests/data/CMC_glb_TMP_TGL_2_latlon.15x.15_2020081000_P000.grib2 - options: - DATA_ENCODING: COMPLEX_PACKING format: name: GRIB mimetype: application/x-grib2