From 700ad0e155c4752f9092a541735ee1f54e2b654b Mon Sep 17 00:00:00 2001 From: Annette Stellema Date: Fri, 5 Jul 2024 14:12:55 +1000 Subject: [PATCH 1/3] Update pre-commit Run pre-commit autoupdate and update .github/workflows/pre-commit.yml --- .github/workflows/pre-commit.yml | 4 ++-- .pre-commit-config.yaml | 4 ++-- unseen/bootstrap.py | 15 ++++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 9e52050..ad89a90 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -5,6 +5,6 @@ jobs: lint: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5be678a..9ec7ecc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,11 @@ repos: - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.4.2 hooks: - id: black language_version: python3 - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.1.0 hooks: - id: flake8 language_version: python3 diff --git a/unseen/bootstrap.py b/unseen/bootstrap.py index ee20f66..4271dc0 100644 --- a/unseen/bootstrap.py +++ b/unseen/bootstrap.py @@ -68,12 +68,17 @@ def random_resample( ) ] args_sub = [ - xr.concat( - [obj.isel({dim: random_sample}) for random_sample in random_samples], - dim=dim, + ( + xr.concat( + [ + obj.isel({dim: random_sample}) + for random_sample in random_samples + ], + dim=dim, + ) + if dim in obj.dims + else obj ) - if dim in obj.dims - else obj for obj in args_sub ] From 726565e4967a4e0ab5f5e930cd3dbb27c2472e30 Mon Sep 17 00:00:00 2001 From: Annette Stellema Date: Fri, 5 Jul 2024 14:18:05 +1000 Subject: [PATCH 2/3] Update eva.py Fix bug if core_dim=None --- unseen/eva.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unseen/eva.py b/unseen/eva.py index 975cbce..921c29b 100644 --- a/unseen/eva.py +++ b/unseen/eva.py @@ -357,7 +357,7 @@ def _fit( covariate = _format_covariate(data, covariate, stationary, core_dim) # Input core dimensions - if hasattr(covariate, core_dim): + if core_dim is not None and hasattr(covariate, core_dim): # Covariate has the same core dimension as data input_core_dims = [[core_dim], [core_dim]] else: From a858f6bda40f495a4aac242dc2e96ed6aa64e1b6 Mon Sep 17 00:00:00 2001 From: Annette Stellema Date: Fri, 5 Jul 2024 14:19:50 +1000 Subject: [PATCH 3/3] Update _fix_metadata --- unseen/fileio.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/unseen/fileio.py b/unseen/fileio.py index 7e168cb..3a0cd4a 100644 --- a/unseen/fileio.py +++ b/unseen/fileio.py @@ -456,10 +456,8 @@ def _fix_metadata(ds, metadata_file): if "rename" in metadata_dict: for orig_var, target_var in metadata_dict["rename"].items(): - try: + if orig_var in ds: ds = ds.rename({orig_var: target_var}) - except ValueError: - pass if "drop_coords" in metadata_dict: for drop_coord in metadata_dict["drop_coords"]: @@ -472,7 +470,8 @@ def _fix_metadata(ds, metadata_file): if "units" in metadata_dict: for var, units in metadata_dict["units"].items(): - ds[var].attrs["units"] = units + if var in ds.data_vars: + ds[var].attrs["units"] = units return ds