From 818a108793804ab15d0569c4642c631d279a69f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Dupuis?= Date: Fri, 25 Oct 2024 11:08:46 -0400 Subject: [PATCH] remove Union --- src/xscen/aggregate.py | 2 +- src/xscen/catalog.py | 4 ++-- src/xscen/diagnostics.py | 8 +++----- src/xscen/indicators.py | 4 ++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/xscen/aggregate.py b/src/xscen/aggregate.py index 756e8bb5..32a9e187 100644 --- a/src/xscen/aggregate.py +++ b/src/xscen/aggregate.py @@ -952,7 +952,7 @@ def produce_horizon( # noqa: C901 ---------- ds : xr.Dataset Input dataset with a time dimension. - indicators : Union[str, os.PathLike, Sequence[Indicator], Sequence[Tuple[str, Indicator]], ModuleType] + indicators : str | os.PathLike | Sequence[Indicator] | Sequence[Tuple[str, Indicator]] | ModuleType Indicators to compute. It will be passed to the `indicators` argument of `xs.compute_indicators`. periods : list of str or list of lists of str, optional Either [start, end] or list of [start_year, end_year] for the period(s) to be evaluated. diff --git a/src/xscen/catalog.py b/src/xscen/catalog.py index 08690228..a8445912 100644 --- a/src/xscen/catalog.py +++ b/src/xscen/catalog.py @@ -778,7 +778,7 @@ def update( Parameters ---------- - df : Union[DataCatalog, intake_esm.esm_datastore, pd.DataFrame, pd.Series, Sequence[pd.Series]], optional + df : DataCatalog | intake_esm.esm_datastore | pd.DataFrame | pd.Series | Sequence[pd.Series], optional Data to be added to the catalog. If None, nothing is added, but the catalog is still updated. """ # Append the new DataFrame or Series @@ -999,7 +999,7 @@ def unstack_id(df: pd.DataFrame | ProjectCatalog | DataCatalog) -> dict: Parameters ---------- - df : Union[pd.DataFrame, ProjectCatalog, DataCatalog] + df : pd.DataFrame | ProjectCatalog | DataCatalog Either a Project/DataCatalog or a pandas DataFrame. Returns diff --git a/src/xscen/diagnostics.py b/src/xscen/diagnostics.py index 89af5733..dbd4b563 100644 --- a/src/xscen/diagnostics.py +++ b/src/xscen/diagnostics.py @@ -7,8 +7,6 @@ from copy import deepcopy from pathlib import Path from types import ModuleType -from typing import Union - import numpy as np import xarray as xr @@ -332,7 +330,7 @@ def properties_and_measures( # noqa: C901 ---------- ds : xr.Dataset Input dataset. - properties : Union[str, os.PathLike, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType] + properties : str | os.PathLike | Sequence[Indicator] | Sequence[tuple[str, Indicator]] | ModuleType Path to a YAML file that instructs on how to calculate properties. Can be the indicator module directly, or a sequence of indicators or a sequence of tuples (indicator name, indicator) as returned by `iter_indicators()`. @@ -535,7 +533,7 @@ def measures_heatmap( def measures_improvement( - meas_datasets: Union[list[xr.Dataset], dict], + meas_datasets: list[xr.Dataset] | dict, dim: str | Sequence[str] | None = None, to_level: str = "diag-improved", ) -> xr.Dataset: @@ -544,7 +542,7 @@ def measures_improvement( Parameters ---------- - meas_datasets: list of xr.Dataset or dict + meas_datasets: list[xr.Dataset] | dict List of 2 datasets: Initial dataset of measures and final (improved) dataset of measures. Both datasets must have the same variables. It is also possible to pass a dictionary where the values are the datasets and the key are not used. diff --git a/src/xscen/indicators.py b/src/xscen/indicators.py index 35bbe40d..68f096ab 100644 --- a/src/xscen/indicators.py +++ b/src/xscen/indicators.py @@ -123,7 +123,7 @@ def compute_indicators( # noqa: C901 ---------- ds : xr.Dataset Dataset to use for the indicators. - indicators : Union[str, os.PathLike, Sequence[Indicator], Sequence[tuple[str, Indicator]], ModuleType] + indicators : str | os.PathLike | Sequence[Indicator] | Sequence[tuple[str, Indicator]] | ModuleType Path to a YAML file that instructs on how to calculate missing variables. Can also be only the "stem", if translations and custom indices are implemented. Can be the indicator module directly, or a sequence of indicators or a sequence of @@ -349,7 +349,7 @@ def select_inds_for_avail_vars( ---------- ds : xr.Dataset Dataset to use for the indicators. - indicators : Union[str, os.PathLike, Sequence[Indicator], Sequence[Tuple[str, Indicator]]] + indicators : str | os.PathLike | Sequence[Indicator] | Sequence[Tuple[str, Indicator]] Path to a YAML file that instructs on how to calculate indicators. Can also be only the "stem", if translations and custom indices are implemented. Can be the indicator module directly, or a sequence of indicators or a sequence of