From 9da2712be78b88a90f4437fdb1aa8fe116dce7d3 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Mon, 13 Nov 2023 15:21:22 +0100 Subject: [PATCH] support for shapefile --- .cruft.json | 2 +- .github/workflows/on-push.yml | 6 +++++- .pre-commit-config.yaml | 9 +++------ c3s_eqc_automatic_quality_control/_regrid.py | 2 +- c3s_eqc_automatic_quality_control/download.py | 8 ++++++-- pyproject.toml | 8 ++++++-- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.cruft.json b/.cruft.json index f8d41e9..3c01a6e 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/ecmwf-projects/cookiecutter-conda-package", - "commit": "baa719b04376f091dee7b3f221d3b62eb29d2f95", + "commit": "77c7df5dde1ef90c38d872967939881aa2d7be71", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index 40463b7..d378c50 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -188,7 +188,11 @@ jobs: upload-to-pypi: runs-on: ubuntu-latest needs: distribution - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') + if: | + always() && + needs.distribution.result == 'success' && + github.event_name == 'push' && + startsWith(github.ref, 'refs/tags') environment: name: pypi url: https://pypi.org/p/c3s-eqc-automatic-quality-control diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 057e311..1e5dd2a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -10,20 +10,17 @@ repos: - id: check-added-large-files - id: debug-statements - id: mixed-line-ending -- repo: https://github.com/psf/black - rev: 23.10.1 - hooks: - - id: black - repo: https://github.com/keewis/blackdoc - rev: v0.3.8 + rev: v0.3.9 hooks: - id: blackdoc additional_dependencies: [black==22.3.0] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.3 + rev: v0.1.5 hooks: - id: ruff args: [--fix, --show-fixes] + - id: ruff-format - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 hooks: diff --git a/c3s_eqc_automatic_quality_control/_regrid.py b/c3s_eqc_automatic_quality_control/_regrid.py index 3ee3edd..855df62 100644 --- a/c3s_eqc_automatic_quality_control/_regrid.py +++ b/c3s_eqc_automatic_quality_control/_regrid.py @@ -31,7 +31,7 @@ def cached_regridder( grid_in: xr.Dataset | xr.DataArray, grid_out: xr.Dataset | xr.DataArray, method: str, - **kwargs: Any + **kwargs: Any, ) -> xe.Regridder: if isinstance(grid_in, xr.Dataset): # Remove bounds attributes, they can generate conflicts diff --git a/c3s_eqc_automatic_quality_control/download.py b/c3s_eqc_automatic_quality_control/download.py index e639c6a..b44b994 100644 --- a/c3s_eqc_automatic_quality_control/download.py +++ b/c3s_eqc_automatic_quality_control/download.py @@ -305,7 +305,7 @@ def get_sources( ) -> list[str]: source: set[str] = set() - for request in request_list if len(request_list) == 1 else tqdm.tqdm(request_list): + for request in tqdm.tqdm(request_list, disable=len(request_list) <= 1): data = _cached_retrieve(collection_id, request) if content := getattr(data, "_content", None): source.update(map(str, content)) @@ -431,7 +431,11 @@ def _download_and_transform_requests( if use_emohawk: data = get_data(sources) - ds: xr.Dataset = data.to_xarray( + if isinstance(data, emohawk.readers.shapefile.ShapefileReader): + to_xarray = data.to_pandas().to_xarray + else: + to_xarray = data.to_xarray + ds: xr.Dataset = to_xarray( xarray_open_mfdataset_kwargs=open_mfdataset_kwargs, **TO_XARRAY_KWARGS, ) diff --git a/pyproject.toml b/pyproject.toml index f118a54..60507a1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,8 +49,9 @@ ignore = [ # pydocstyle: Missing Docstrings "D1" ] -# Black line length is 88, but black does not format comments. -line-length = 110 +# Same as Black. +indent-width = 4 +line-length = 88 select = [ # pyflakes "F", @@ -66,6 +67,9 @@ select = [ ] target-version = "py310" +[tool.ruff.lint.pycodestyle] +max-line-length = 110 + [tool.ruff.pydocstyle] convention = "numpy"