From af19fc1588e739f975da8d9f072ab93d343c23a9 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Mon, 12 Feb 2024 15:01:42 +0100 Subject: [PATCH 1/4] address warnings --- c3s_eqc_automatic_quality_control/_time_weighted.py | 4 +++- c3s_eqc_automatic_quality_control/plot.py | 8 ++++---- tests/test_20_diagnostics.py | 2 +- tests/test_22_spatial_diagnostics.py | 4 +--- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/c3s_eqc_automatic_quality_control/_time_weighted.py b/c3s_eqc_automatic_quality_control/_time_weighted.py index 7f6e273..9926f55 100644 --- a/c3s_eqc_automatic_quality_control/_time_weighted.py +++ b/c3s_eqc_automatic_quality_control/_time_weighted.py @@ -59,7 +59,9 @@ def groupby_reduce( obj = self.obj if isinstance(self.obj_weighted, (DataArrayWeighted | DatasetWeighted)): obj = obj.assign_coords(__weights__=self.obj_weighted.weights) - return obj.groupby(group).map(map_func, (time_name, func_name), **kwargs) + return obj.groupby(group, squeeze=False).map( + map_func, (time_name, func_name), **kwargs + ) @utils.keep_attrs def reduce( diff --git a/c3s_eqc_automatic_quality_control/plot.py b/c3s_eqc_automatic_quality_control/plot.py index 2531f97..24f1239 100644 --- a/c3s_eqc_automatic_quality_control/plot.py +++ b/c3s_eqc_automatic_quality_control/plot.py @@ -84,9 +84,9 @@ def shaded_std( colors = iter(colors) if hue_dim: - _, means = zip(*ds_mean.groupby(hue_dim)) + _, means = zip(*ds_mean.groupby(hue_dim, squeeze=False)) if ds_std: - _, stds = zip(*ds_std.groupby(hue_dim)) + _, stds = zip(*ds_std.groupby(hue_dim, squeeze=False)) else: stds = tuple(xr.Dataset() for _ in range(len(means))) else: @@ -250,7 +250,7 @@ def projected_map( txt = "\n".join( [ f"{k:>{n_characters}}: {v.squeeze().values:+e}{units}" - for k, v in da_stats.groupby("diagnostic") + for k, v in da_stats.groupby("diagnostic", squeeze=False) ] ) plt.figtext( @@ -455,4 +455,4 @@ def seasonal_boxplot( da = da.stack(stacked_dim=da.dims) df = da.to_dataframe() - return df.groupby(by=da[time_dim].dt.season.values).boxplot(**kwargs) + return df.groupby(by=da[time_dim].dt.season.values, squeeze=False).boxplot(**kwargs) diff --git a/tests/test_20_diagnostics.py b/tests/test_20_diagnostics.py index 73af3b7..2b4788e 100644 --- a/tests/test_20_diagnostics.py +++ b/tests/test_20_diagnostics.py @@ -31,7 +31,7 @@ def test_regrid(self, obj: xr.DataArray | xr.Dataset) -> None: fs, dirname = cacholote.utils.get_cache_files_fs_dirname() assert fs.ls(dirname) == [] # cache is empty - for _, obj in obj.isel(time=slice(2)).groupby("time"): + for _, obj in obj.isel(time=slice(2)).groupby("time", squeeze=False): expected = obj.isel(longitude=slice(10), latitude=slice(10)) actual = diagnostics.regrid(obj, expected, "nearest_s2d") xr.testing.assert_equal(actual, expected) diff --git a/tests/test_22_spatial_diagnostics.py b/tests/test_22_spatial_diagnostics.py index 5a43f37..1de388d 100644 --- a/tests/test_22_spatial_diagnostics.py +++ b/tests/test_22_spatial_diagnostics.py @@ -115,8 +115,6 @@ def test_spatial_weighted_rmse_against_sklearn() -> None: da1 = da da2 = da**2 - expected = sklearn.metrics.mean_squared_error( - da1, da2, sample_weight=weights, squared=False - ) + expected = sklearn.metrics.root_mean_squared_error(da1, da2, sample_weight=weights) actual = diagnostics.spatial_weighted_rmse(da1, da2) assert expected == actual.values From 524eea295ceca96e5950770bae2117318d959484 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Fri, 12 Apr 2024 12:33:40 +0200 Subject: [PATCH 2/4] add import --- c3s_eqc_automatic_quality_control/download.py | 1 + 1 file changed, 1 insertion(+) diff --git a/c3s_eqc_automatic_quality_control/download.py b/c3s_eqc_automatic_quality_control/download.py index ea0afa7..dd3aa3d 100644 --- a/c3s_eqc_automatic_quality_control/download.py +++ b/c3s_eqc_automatic_quality_control/download.py @@ -30,6 +30,7 @@ import cf_xarray # noqa: F401 import cgul import emohawk.readers.directory +import emohawk.readers.shapefile import joblib import pandas as pd import tqdm From fa2450a70cce739a1261c21bc916bd528d253fb7 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Fri, 12 Apr 2024 13:23:41 +0200 Subject: [PATCH 3/4] fix pandas and cartopy --- c3s_eqc_automatic_quality_control/plot.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/c3s_eqc_automatic_quality_control/plot.py b/c3s_eqc_automatic_quality_control/plot.py index 24f1239..6d5775f 100644 --- a/c3s_eqc_automatic_quality_control/plot.py +++ b/c3s_eqc_automatic_quality_control/plot.py @@ -31,6 +31,7 @@ import plotly.graph_objs as go import xarray as xr from cartopy.mpl.geocollection import GeoQuadMesh +from cartopy.mpl.gridliner import Gridliner from matplotlib.typing import ColorType from xarray.plot.facetgrid import FacetGrid @@ -218,11 +219,13 @@ def projected_map( ax.gridlines(draw_labels=False) for ax in plot_obj.axs[-1, :]: - for gl in ax._gridliners: + gridliners = [a for a in ax.artists if isinstance(a, Gridliner)] + for gl in gridliners: gl.bottom_labels = True for ax in plot_obj.axs[:, 0]: - for gl in ax._gridliners: + gridliners = [a for a in ax.artists if isinstance(a, Gridliner)] + for gl in gridliners: gl.left_labels = True if show_stats: @@ -231,7 +234,8 @@ def projected_map( ) else: plot_obj.axes.coastlines() - if not getattr(plot_obj.axes, "_gridliners", []): + gridliners = [a for a in plot_obj.axes.artists if isinstance(a, Gridliner)] + if not gridliners: gl = plot_obj.axes.gridlines(draw_labels=True) gl.top_labels = gl.right_labels = False @@ -454,5 +458,4 @@ def seasonal_boxplot( da = da.stack(stacked_dim=da.dims) df = da.to_dataframe() - - return df.groupby(by=da[time_dim].dt.season.values, squeeze=False).boxplot(**kwargs) + return df.groupby(by=da[time_dim].dt.season.values).boxplot(**kwargs) From 356e2806ccaf77a05d6a3e18e3ec11b8570b2ea6 Mon Sep 17 00:00:00 2001 From: Mattia Almansi Date: Mon, 15 Apr 2024 11:44:01 +0200 Subject: [PATCH 4/4] template update --- .cruft.json | 2 +- .github/workflows/on-push.yml | 4 ++-- .pre-commit-config.yaml | 6 +++--- c3s_eqc_automatic_quality_control/_time_weighted.py | 6 ++---- tests/test_21_time_diagnostics.py | 12 ++++-------- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.cruft.json b/.cruft.json index b522a23..f0b22fe 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "https://github.com/ecmwf-projects/cookiecutter-conda-package", - "commit": "54a28e5611040c398c74454de4e6147c79cb5a39", + "commit": "280417918dc86a2f2be417c8877a590c07cf2a1c", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index f3e14ea..8b2dbc9 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -26,7 +26,7 @@ jobs: - uses: actions/setup-python@v5 with: python-version: 3.x - - uses: pre-commit/action@v3.0.0 + - uses: pre-commit/action@v3.0.1 combine-environments: runs-on: ubuntu-latest @@ -230,6 +230,6 @@ jobs: with: name: distribution path: dist - - uses: pypa/gh-action-pypi-publish@v1.8.11 + - uses: pypa/gh-action-pypi-publish@v1.8.14 with: verbose: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c70baef..ec36f1c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -17,7 +17,7 @@ repos: - id: blackdoc additional_dependencies: [black==23.11.0] - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.2.0 + rev: v0.3.7 hooks: - id: ruff args: [--fix, --show-fixes] @@ -27,7 +27,7 @@ repos: hooks: - id: mdformat - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks - rev: v2.12.0 + rev: v2.13.0 hooks: - id: pretty-format-yaml args: [--autofix, --preserve-quotes] diff --git a/c3s_eqc_automatic_quality_control/_time_weighted.py b/c3s_eqc_automatic_quality_control/_time_weighted.py index 9926f55..1634e55 100644 --- a/c3s_eqc_automatic_quality_control/_time_weighted.py +++ b/c3s_eqc_automatic_quality_control/_time_weighted.py @@ -145,8 +145,7 @@ def map_func( time_name: str, func: str, **kwargs: Any, -) -> xr.DataArray: - ... +) -> xr.DataArray: ... @overload @@ -155,8 +154,7 @@ def map_func( time_name: str, func: str, **kwargs: Any, -) -> xr.Dataset: - ... +) -> xr.Dataset: ... def map_func( diff --git a/tests/test_21_time_diagnostics.py b/tests/test_21_time_diagnostics.py index 2211d78..e58a7e6 100644 --- a/tests/test_21_time_diagnostics.py +++ b/tests/test_21_time_diagnostics.py @@ -9,13 +9,11 @@ @overload -def weighted_mean(obj: xr.DataArray) -> xr.DataArray: - ... +def weighted_mean(obj: xr.DataArray) -> xr.DataArray: ... @overload -def weighted_mean(obj: xr.Dataset) -> xr.Dataset: - ... +def weighted_mean(obj: xr.Dataset) -> xr.Dataset: ... def weighted_mean(obj: xr.DataArray | xr.Dataset) -> xr.DataArray | xr.Dataset: @@ -25,13 +23,11 @@ def weighted_mean(obj: xr.DataArray | xr.Dataset) -> xr.DataArray | xr.Dataset: @overload -def weighted_std(obj: xr.DataArray) -> xr.DataArray: - ... +def weighted_std(obj: xr.DataArray) -> xr.DataArray: ... @overload -def weighted_std(obj: xr.Dataset) -> xr.Dataset: - ... +def weighted_std(obj: xr.Dataset) -> xr.Dataset: ... def weighted_std(obj: xr.DataArray | xr.Dataset) -> xr.DataArray | xr.Dataset: