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

[pre-commit.ci] pre-commit autoupdate #860

Merged
merged 13 commits into from
Jul 4, 2024
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-added-large-files
- id: check-docstring-first
Expand All @@ -22,12 +22,12 @@ repos:
- id: trailing-whitespace

- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.3.0
rev: 24.4.2
hooks:
- id: black

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.0
hooks:
- id: flake8

Expand All @@ -40,10 +40,10 @@ repos:
rev: v0.3.9
hooks:
- id: blackdoc
additional_dependencies: [ 'black==23.10.1' ]
additional_dependencies: [ 'black==24.4.2' ]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.9.0
rev: v1.10.1
hooks:
- id: mypy
exclude: 'asv_bench'
Expand All @@ -55,7 +55,7 @@ repos:
types-pytz,
typing-extensions,
# Dependencies that are typed
numpy,
numpy
]

- repo: https://github.com/python-jsonschema/check-jsonschema
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Internals/Minor Fixes
---------------------
- Fixed some issues with the documentation build to address rendering errors and reduce the number of warnings on ReadTheDocs. (pr:`843`) `Trevor James Smith`_
- Fixed some issues with the typing hints of classes functions. (pr:`850`) `Trevor James Smith`_
- Fixed several issues with incompatible dependency configurations in the CI and addressed a few deprecations. (pr:`861`) `Trevor James Smith`_

climpred v2.4.0 (2023-11-09)
============================
Expand Down
13 changes: 7 additions & 6 deletions ci/requirements/climpred-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- conda-forge
- nodefaults
dependencies:
- python >=3.9,<3.12
- python >=3.9,<3.13
# Documentation
- myst-nb
- nbstripout
Expand All @@ -23,13 +23,13 @@ dependencies:
# Miscellaneous
- cftime >=1.5.0
# Numerics
- numpy
- numpy >=1.25.0
- pandas
- scipy
- xarray
- xarray >=2022.6.0
# Package Management
- asv
- black==19.10b0
- black ==24.4.2
- coveralls
- flake8
- isort
Expand All @@ -46,13 +46,14 @@ dependencies:
- dask-core
- numba
# Regridding
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- xesmf
# Statistics
- bias_correction
- eofs
- esmtools >=1.1.3
- xclim >=0.30.0
- xclim >=0.46.0
- xrft
- xskillscore >=0.0.20
# Visualization
Expand Down
4 changes: 3 additions & 1 deletion ci/requirements/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ dependencies:
- tqdm
# optionals
- bias_correction
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- esmtools
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- nc-time-axis >=1.4.0
- numba >=0.52
- numpy >=1.25.0
- xclim
- xesmf
- xrft
10 changes: 6 additions & 4 deletions ci/requirements/maximum-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,22 @@ dependencies:
- coveralls
- dask-core
- eofs
- esmpy=*=mpi* # Ensures MPI works with version of esmpy.
- esmpy =*=mpi* # Ensures MPI works with version of esmpy.
- h5netcdf
- importlib-metadata <8.0.0 # Pin needed for esmpy compatibility. See: https://github.com/pangeo-data/xESMF/issues/374
- matplotlib-base
- nc-time-axis >=1.4.0
- h5netcdf
- numpy >=1.25.0
- pip
- pooch
- pytest<8
- pytest <8.0.0
- pytest-cov
- pytest-lazy-fixture
- pytest-xdist
- scipy
- tqdm
- xarray >=2022.6.0
- xclim >=0.46
- xarray
- xesmf
- xrft
- xskillscore >=0.0.18
7 changes: 4 additions & 3 deletions ci/requirements/minimum-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ dependencies:
- coveralls
- dask-core
- h5netcdf
- numpy >=1.25.0
- pip
- pooch
- pytest<8
- pytest <8.0.0
- pytest-cov
- pytest-lazy-fixture
- pytest-xdist
- scipy
- xarray
- xskillscore >=0.0.18
- tqdm
- xarray >=0.19.0
- xskillscore >=0.0.18
8 changes: 4 additions & 4 deletions climpred/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,20 @@ def _chunk_before_resample_iterations_idx(
if isinstance(chunking_dims, str):
chunking_dims = [chunking_dims]
# size of CLIMPRED_DIMS
climpred_dim_chunksize = 8 * np.product(
climpred_dim_chunksize = 8 * np.prod(
np.array([ds[d].size for d in CLIMPRED_DIMS if d in ds.dims])
)
# remaining blocksize for remaining dims considering iteration
spatial_dim_blocksize = optimal_blocksize / (climpred_dim_chunksize * iterations)
# size of remaining dims
chunking_dims_size = np.product(
chunking_dims_size = np.prod(
np.array([ds[d].size for d in ds.dims if d not in CLIMPRED_DIMS])
) # ds.lat.size*ds.lon.size
# chunks needed to get to optimal blocksize
chunks_needed = chunking_dims_size / spatial_dim_blocksize
# get size clon, clat for spatial chunks
cdim = [1 for i in chunking_dims]
nchunks = np.product(cdim)
nchunks = np.prod(cdim)
stepsize = 1
counter = 0
while nchunks < chunks_needed:
Expand All @@ -444,7 +444,7 @@ def _chunk_before_resample_iterations_idx(
if c <= ds[d].size:
c = c + stepsize
cdim[i] = c
nchunks = np.product(cdim)
nchunks = np.prod(cdim)
counter += 1
if counter == 100:
break
Expand Down
10 changes: 5 additions & 5 deletions climpred/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,16 +908,16 @@ def remove_seasonality(
>>> HindcastEnsemble.remove_seasonality(seasonality="month")
<climpred.HindcastEnsemble>
Initialized:
SST (init, lead, member) float64 -0.2349 -0.216 ... 0.6476 0.6433
SST (init, lead, member) float64 -0.2392 -0.2203 ... 0.618 0.6136
Uninitialized:
SST (time, member) float64 -0.1789 0.005732 -0.257 ... 0.4359 0.4154
SST (time, member) float64 -0.1969 -0.01221 -0.275 ... 0.4179 0.3974
Observations:
SST (time) float32 -0.3739 -0.3248 -0.1575 ... 0.2757 0.3736 0.4778
SST (time) float32 -0.4015 -0.3524 -0.1851 ... 0.2481 0.346 0.4502
"""

def _remove_seasonality(ds, initialized_dim="init", seasonality=None):
"""Remove the seasonal cycle from the data."""
if ds is {}:
if ds == {}:
return {}
if seasonality is None:
seasonality = OPTIONS["seasonality"]
Expand Down Expand Up @@ -2829,7 +2829,7 @@ def remove_bias(
else:
raise NotImplementedError(
f"bias removal '{how}' is not implemented, please choose from "
f" {INTERNAL_BIAS_CORRECTION_METHODS+BIAS_CORRECTION_BIAS_CORRECTION_METHODS}." # noqa: E501
f" {INTERNAL_BIAS_CORRECTION_METHODS + BIAS_CORRECTION_BIAS_CORRECTION_METHODS}." # noqa: E501
)

if train_test_split in ["unfair-cv"]:
Expand Down
9 changes: 9 additions & 0 deletions climpred/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import warnings

import numpy as np
import pytest
import xarray as xr
from packaging.version import Version

import climpred
from climpred import HindcastEnsemble, PerfectModelEnsemble
Expand Down Expand Up @@ -319,6 +322,12 @@ def hindcast_S2S_Germany():
def hindcast_NMME_Nino34():
"""NMME hindcasts with monthly leads and monthly inits and related IOv2
observations for SST of the Nino34 region."""
if Version(np.__version__) >= Version("2.0.0") and Version(
xr.__version__
) <= Version("2024.6.0"):
warnings.warn("Skipping test due to incompatible numpy and xarray versions.")
pytest.skip("Changes in numpy>=2.0.0 break xarray<=2024.6.0.")

init = load_dataset("NMME_hindcast_Nino34_sst")
obs = load_dataset("NMME_OIv2_Nino34_sst")
init["sst"].attrs["units"] = "C"
Expand Down
9 changes: 5 additions & 4 deletions climpred/tests/test_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_same_inits_verification_dates(hindcast_hist_obs_1d, caplog):
if i >= 2:
print(record)
assert (
f"verifs: {FIRST_INIT+i}-01-01 00:00:00-{LAST_INIT+i}-01-01"
f"verifs: {FIRST_INIT + i}-01-01 00:00:00-{LAST_INIT + i}-01-01"
in record[2]
)

Expand Down Expand Up @@ -124,7 +124,7 @@ def test_same_verifs_initializations(hindcast_hist_obs_1d, caplog):
if i >= 2:
print(record)
assert (
f"inits: {FIRST_INIT-i}-01-01 00:00:00-{LAST_INIT-i}-01-01 00:00:00"
f"inits: {FIRST_INIT - i}-01-01 00:00:00-{LAST_INIT - i}-01-01 00:00:00"
in record[2]
)

Expand Down Expand Up @@ -156,7 +156,7 @@ def test_maximize_alignment_inits(hindcast_hist_obs_1d, caplog):
if i >= 1:
print(record)
assert (
f"inits: 1954-01-01 00:00:00-{2013-i}-01-01 00:00:00" in record[2]
f"inits: 1954-01-01 00:00:00-{2013 - i}-01-01 00:00:00" in record[2]
)


Expand All @@ -177,7 +177,8 @@ def test_maximize_alignment_verifs(hindcast_hist_obs_1d, caplog):
if i >= 1:
print(record)
assert (
f"verifs: {1956+i}-01-01 00:00:00-2015-01-01 00:00:00" in record[2]
f"verifs: {1956 + i}-01-01 00:00:00-2015-01-01 00:00:00"
in record[2]
)


Expand Down
1 change: 1 addition & 0 deletions climpred/tests/test_bias_removal.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,7 @@ def test_remove_bias_compare_scaling_and_mean(hindcast_recon_1d_mm):

def test_remove_bias_errors(hindcast_NMME_Nino34):
"""Test remove_bias error messaging."""

how = "additive_mean"
he = (
hindcast_NMME_Nino34.sel(lead=[4, 5])
Expand Down
2 changes: 1 addition & 1 deletion climpred/tests/test_lead_time_resolutions.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def test_HindcastEnsemble_lead_pdTimedelta(hind_ds_initialized_1d, lead_res):
initialized = hind_ds_initialized_1d

initialized["lead"] = [
pd.Timedelta(f"{i*n} {freq}") for i in initialized.lead.values
pd.Timedelta(f"{i * n} {freq}") for i in initialized.lead.values
]
hindcast = HindcastEnsemble(initialized)

Expand Down
8 changes: 4 additions & 4 deletions climpred/tests/test_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def test_reset_temporal_axis(PM_ds_control_3d_full):
first_actual = _reset_temporal_axis(
PM_ds_control_3d_full, tsmooth_kws=tsmooth_kws, dim="time"
).time.values[0]
first_expected = f"{first_ori}-{first_ori+smooth*1-1}"
first_expected = f"{first_ori}-{first_ori + smooth * 1 - 1}"
assert first_actual == first_expected


Expand All @@ -40,7 +40,7 @@ def test_reset_temporal_axis_lead(PM_ds_initialized_3d_full):
first_actual = _reset_temporal_axis(
PM_ds_initialized_3d_full, tsmooth_kws=tsmooth_kws
)[dim].values[0]
first_expected = f"{first_ori}-{first_ori+smooth*1-1}"
first_expected = f"{first_ori}-{first_ori + smooth * 1 - 1}"
assert first_actual == first_expected


Expand Down Expand Up @@ -141,7 +141,7 @@ def test_PerfectModelEnsemble_temporal_smoothing_cftime_and_skill(pm, smooth):
assert pm_smoothed._temporally_smoothed
skill = pm_smoothed.verify(metric="acc", comparison="m2e", dim=["member", "init"])
assert skill.lead.size == pm.get_initialized().lead.size - smooth + 1
assert skill.lead[0] == f"1-{1+smooth-1}"
assert skill.lead[0] == f"1-{1 + smooth - 1}"


@pytest.mark.parametrize("dim", ["time", "lead"])
Expand All @@ -166,7 +166,7 @@ def test_HindcastEnsemble_temporal_smoothing_cftime_and_skill(he, smooth, dim):
metric="acc", comparison="e2o", alignment="maximize", dim="init"
)
assert skill.lead.size == he.get_initialized().lead.size - smooth + 1
assert skill.lead[0] == f"1-{1+smooth-1}"
assert skill.lead[0] == f"1-{1 + smooth - 1}"


@requires_xesmf
Expand Down
8 changes: 6 additions & 2 deletions climpred/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ def convert_init_lead_to_valid_time_lead(
[skill.sel(lead=lead).swap_dims({"init": "valid_time"}) for lead in skill.lead],
"lead",
)
return add_init_from_time_lead(swapped.drop("init")).dropna("valid_time", how="all")
return add_init_from_time_lead(swapped.drop_vars("init")).dropna(
"valid_time", how="all"
)


def convert_valid_time_lead_to_init_lead(
Expand Down Expand Up @@ -343,7 +345,9 @@ def convert_valid_time_lead_to_init_lead(
[skill.sel(lead=lead).swap_dims({"valid_time": "init"}) for lead in skill.lead],
"lead",
)
return add_time_from_init_lead(swapped.drop("valid_time")).dropna("init", how="all")
return add_time_from_init_lead(swapped.drop_vars("valid_time")).dropna(
"init", how="all"
)


def find_start_dates_for_given_init(control, single_init):
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cf_xarray>=0.6.0
cftime>=1.5.0
dask>=2021.10.0
numpy
numpy>=1.25.0
packaging
pooch>=1.4
xarray
xarray>=0.19.0
xskillscore>=0.0.20