From 0ccf4a4290722dfa2583247c2a88a616edae6f58 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jan 2024 19:39:30 +0000 Subject: [PATCH 1/3] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.4.0 → v4.5.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.4.0...v4.5.0) - [github.com/psf/black-pre-commit-mirror: 23.10.1 → 23.12.1](https://github.com/psf/black-pre-commit-mirror/compare/23.10.1...23.12.1) - [github.com/PyCQA/isort: 5.12.0 → 5.13.2](https://github.com/PyCQA/isort/compare/5.12.0...5.13.2) - [github.com/keewis/blackdoc: v0.3.8 → v0.3.9](https://github.com/keewis/blackdoc/compare/v0.3.8...v0.3.9) - [github.com/pre-commit/mirrors-mypy: v0.982 → v1.8.0](https://github.com/pre-commit/mirrors-mypy/compare/v0.982...v1.8.0) - [github.com/python-jsonschema/check-jsonschema: 0.27.0 → 0.27.3](https://github.com/python-jsonschema/check-jsonschema/compare/0.27.0...0.27.3) --- .pre-commit-config.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 118cf8a7d..fb111a5c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-added-large-files - id: check-docstring-first @@ -22,7 +22,7 @@ repos: - id: trailing-whitespace - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.10.1 + rev: 23.12.1 hooks: - id: black @@ -32,18 +32,18 @@ repos: - id: flake8 - repo: https://github.com/PyCQA/isort - rev: 5.12.0 + rev: 5.13.2 hooks: - id: isort - repo: https://github.com/keewis/blackdoc - rev: v0.3.8 + rev: v0.3.9 hooks: - id: blackdoc additional_dependencies: [ 'black==23.10.1' ] - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.982 + rev: v1.8.0 hooks: - id: mypy exclude: 'asv_bench' @@ -59,7 +59,7 @@ repos: ] - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.27.0 + rev: 0.27.3 hooks: - id: check-github-workflows - id: check-readthedocs From 098b3dc966ac8b754bb52d0ed0000bd5258d8e7c Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 3 Jan 2024 12:20:05 -0500 Subject: [PATCH 2/3] no longer allow implicit Optional in mypy --- .pre-commit-config.yaml | 6 +-- climpred/classes.py | 90 +++++++++++++++++--------------- climpred/prediction.py | 8 ++- climpred/preprocessing/shared.py | 6 +-- climpred/utils.py | 4 +- 5 files changed, 64 insertions(+), 50 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index fb111a5c6..72ab198ff 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -49,11 +49,11 @@ repos: exclude: 'asv_bench' additional_dependencies: [ # Type stubs - types-python-dateutil, - types-pkg_resources, types-PyYAML, + types-pkg_resources, + types-python-dateutil, types-pytz, - typing-extensions==3.10.0.0, + typing-extensions, # Dependencies that are typed numpy, ] diff --git a/climpred/classes.py b/climpred/classes.py index e932c2c54..30693f39e 100644 --- a/climpred/classes.py +++ b/climpred/classes.py @@ -980,7 +980,7 @@ def _warn_if_chunked_along_init_member_time(self) -> None: ndims.remove(d) if len(ndims) > 0: msg += ( - f"\nConsider chunking embarassingly parallel dimensions such as " + f"\nConsider chunking embarrassingly parallel dimensions such as " f"{ndims} automatically, i.e. " f'`{name}.chunk({ndims[0]}="auto").verify(...).' ) @@ -988,15 +988,16 @@ def _warn_if_chunked_along_init_member_time(self) -> None: def _bootstrap( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, - alignment: alignmentType = None, - reference: referenceType = None, - groupby: groupbyType = None, - iterations: int = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, + alignment: Optional[alignmentType] = None, + reference: Optional[referenceType] = None, + groupby: Optional[groupbyType] = None, + iterations: Optional[int] = None, sig: int = 95, - resample_dim: str = None, + resample_dim: Optional[str] = None, **metric_kwargs: metric_kwargsType, ) -> xr.Dataset: """PredictionEnsemble.bootstrap() parent method. @@ -1167,7 +1168,7 @@ def _bootstrap( ] results_labels = ["verify skill", "low_ci", "high_ci"] - if reference != []: + if reference: pvalue = _pvalue_from_distributions( resampled_skills.drop_sel(skill="initialized"), resampled_skills.sel(skill="initialized"), @@ -1347,11 +1348,12 @@ def get_control(self) -> xr.Dataset: def verify( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, - reference: referenceType = None, - groupby: groupbyType = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, + reference: Optional[referenceType] = None, + groupby: Optional[groupbyType] = None, **metric_kwargs: metric_kwargsType, ) -> xr.Dataset: """Verify initialized predictions against a configuration of its members. @@ -1498,9 +1500,10 @@ def verify( def _compute_uninitialized( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, **metric_kwargs: metric_kwargsType, ) -> xr.Dataset: """Verify the bootstrapped uninitialized run against itself. @@ -1554,8 +1557,9 @@ def _compute_uninitialized( def _compute_persistence( self, - metric: metricType = None, - dim: dimType = None, + *, + metric: metricType, + dim: Optional[dimType] = None, **metric_kwargs: metric_kwargsType, ): """Verify a simple persistence forecast of the control run against itself. @@ -1630,9 +1634,10 @@ def _compute_persistence( def _compute_climatology( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, **metric_kwargs: metric_kwargsType, ) -> xr.Dataset: """Verify a climatology forecast. @@ -1681,11 +1686,12 @@ def _compute_climatology( def bootstrap( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, - reference: referenceType = None, - groupby: groupbyType = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, + reference: Optional[referenceType] = None, + groupby: Optional[groupbyType] = None, iterations: Optional[int] = None, sig: int = 95, resample_dim: str = "member", @@ -2102,12 +2108,13 @@ def plot_alignment( def verify( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, - alignment: alignmentType = None, - reference: referenceType = None, - groupby: groupbyType = None, + *, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, + alignment: Optional[alignmentType] = None, + reference: Optional[referenceType] = None, + groupby: Optional[groupbyType] = None, **metric_kwargs: metric_kwargsType, ) -> xr.Dataset: """Verify the initialized ensemble against observations. @@ -2409,12 +2416,13 @@ def _verify( def bootstrap( self, - metric: metricType = None, - comparison: comparisonType = None, - dim: dimType = None, - alignment: alignmentType = None, - reference: referenceType = None, - groupby: groupbyType = None, + *, + alignment: alignmentType, + metric: metricType, + comparison: comparisonType, + dim: Optional[dimType] = None, + reference: Optional[referenceType] = None, + groupby: Optional[groupbyType] = None, iterations: Optional[int] = None, sig: int = 95, resample_dim: str = "member", @@ -2541,7 +2549,7 @@ def bootstrap( def remove_bias( self, - alignment: alignmentType = None, + alignment: alignmentType, how: str = "additive_mean", train_test_split: str = "unfair", train_init: Optional[Union[xr.DataArray, slice]] = None, diff --git a/climpred/prediction.py b/climpred/prediction.py index 7f67eff9c..692a7a2c0 100644 --- a/climpred/prediction.py +++ b/climpred/prediction.py @@ -144,7 +144,13 @@ def _sanitize_to_list(dim: Union[str, Set, Tuple, List, None]) -> Optional[List[ return dim -def _get_metric_comparison_dim(initialized, metric, comparison, dim, kind): +def _get_metric_comparison_dim( + initialized, + metric, + comparison, + dim: Optional[Union[List[str], str]], + kind, +): """Return `metric`, `comparison` and `dim` for compute functions. Args: diff --git a/climpred/preprocessing/shared.py b/climpred/preprocessing/shared.py index 969e36082..c6d91a257 100644 --- a/climpred/preprocessing/shared.py +++ b/climpred/preprocessing/shared.py @@ -1,4 +1,4 @@ -from typing import Any, Callable, Union +from typing import Any, Callable, Optional, Union import numpy as np import xarray as xr @@ -10,10 +10,10 @@ def load_hindcast( inits=range(1961, 1965, 1), members=range(1, 3, 1), - preprocess: Callable = None, + preprocess: Optional[Callable] = None, lead_offset: int = 1, parallel: bool = True, - engine: str = None, + engine: Optional[str] = None, get_path: Callable = get_path_mpi, **get_path_kwargs: Any, ) -> Union[xr.DataArray, xr.Dataset]: diff --git a/climpred/utils.py b/climpred/utils.py index 74a81fe83..c618a42b0 100644 --- a/climpred/utils.py +++ b/climpred/utils.py @@ -64,7 +64,7 @@ def assign_attrs( dim=None, **kwargs, ): - """Write information about prediction skill into attrs. + r"""Write information about prediction skill into attrs. Args: skill (`xarray` object): prediction skill. @@ -75,7 +75,7 @@ def assign_attrs( metric (class) : metric used in comparing the forecast and verification data. comparison (class): how to compare the forecast and verification data. dim (str): Dimension over which metric was applied. - kwargs (dict): other information + \*\*kwargs : other information Returns: skill (`xarray` object): prediction skill with additional attrs. From daf66d419ad28f4be857701e409b3f5e06aa3229 Mon Sep 17 00:00:00 2001 From: Zeitsperre <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 5 Jan 2024 14:15:55 -0500 Subject: [PATCH 3/3] update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 41ba11f19..ea8850c00 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -20,6 +20,7 @@ climpred v2.5.0 (unreleased) 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`_ climpred v2.4.0 (2023-11-09) ============================