From b6e73ac62ec1045478d028c33ee514ea02c20a08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gratien=20D=C3=A9sormeaux?= Date: Thu, 12 Dec 2024 17:59:31 +0100 Subject: [PATCH] Mypy fixes --- src/meteole/forecast.py | 23 +++++++++++------------ src/meteole/raster.py | 4 +--- src/meteole/vigilance.py | 3 +-- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/meteole/forecast.py b/src/meteole/forecast.py index 738bfdc..38a58e2 100644 --- a/src/meteole/forecast.py +++ b/src/meteole/forecast.py @@ -6,7 +6,6 @@ import tempfile from abc import abstractmethod from pathlib import Path -from typing import Dict, List, Optional import pandas as pd import xarray as xr @@ -59,7 +58,7 @@ def __init__( self.precision = precision self._validate_parameters() - self.folderpath: Optional[Path] = None + self.folderpath: Path | None = None self.get_capabilities() def get_capabilities(self) -> pd.DataFrame: @@ -111,7 +110,7 @@ def _get_available_feature(grid_axis, feature_name): features = [int(feature) for feature in features] return features - def get_coverage_description(self, coverage_id: str) -> Dict: + def get_coverage_description(self, coverage_id: str) -> dict: """This endpoint returns the available axis (times, heights) to properly query coverage TODO: other informations can be fetched from this endpoint, not yet implemented. @@ -136,7 +135,7 @@ def get_coverage_description(self, coverage_id: str) -> Dict: def get_coverages( self, - coverage_ids: List[str], + coverage_ids: list[str], lat: tuple = const.FRANCE_METRO_LATITUDES, long: tuple = const.FRANCE_METRO_LONGITUDES, ) -> pd.DataFrame: @@ -159,8 +158,8 @@ def get_coverages( def _get_coverage_id( self, indicator: str, - run: Optional[str] = None, - interval: Optional[str] = None, + run: str | None = None, + interval: str | None = None, ) -> str: """ Get a coverage_id from `capabilities`. @@ -234,9 +233,9 @@ def get_coverage( indicator: str | None = None, lat: tuple = const.FRANCE_METRO_LATITUDES, long: tuple = const.FRANCE_METRO_LONGITUDES, - heights: List[int] | None = None, - pressures: List[int] | None = None, - forecast_horizons: List[int] | None = None, + heights: list[int] | None = None, + pressures: list[int] | None = None, + forecast_horizons: list[int] | None = None, run: str | None = None, interval: str | None = None, coverage_id: str = "", @@ -288,8 +287,8 @@ def get_coverage( return pd.concat(df_list, axis=0).reset_index(drop=True) def _raise_if_invalid_or_fetch_default( - self, param_name: str, inputs: List[int] | None, availables: List[int] - ) -> List[int]: + self, param_name: str, inputs: list[int] | None, availables: list[int] + ) -> list[int]: """ Checks if the elements in `inputs` are in `availables` and raises a ValueError if not. If `inputs` is empty or None, uses the first element from `availables` as the default value. @@ -345,7 +344,7 @@ def instant_indicators(self) -> str: """The list of instant indicators""" pass - def _get_capabilities(self) -> Dict: + def _get_capabilities(self) -> dict: """The Capabilities of the AROME/ARPEGE service.""" url = f"{self.base_url}/{self.entry_point}/GetCapabilities" diff --git a/src/meteole/raster.py b/src/meteole/raster.py index 0c8733d..9f26ed9 100644 --- a/src/meteole/raster.py +++ b/src/meteole/raster.py @@ -1,6 +1,4 @@ """Functionnalities to deal with the raster data""" -from typing import Optional - import cartopy.crs as ccrs import matplotlib.pyplot as plt import rasterio @@ -19,7 +17,7 @@ def plot_tiff_file( filename, data_type: str, unit: str, - title: Optional[str] = None, + title: str | None = None, ): """ Plot a tiff file. diff --git a/src/meteole/vigilance.py b/src/meteole/vigilance.py index f3ccbff..0c3bdf3 100644 --- a/src/meteole/vigilance.py +++ b/src/meteole/vigilance.py @@ -1,6 +1,5 @@ import logging from io import BytesIO -from typing import Tuple import matplotlib.image as mpimg import matplotlib.pyplot as plt @@ -89,7 +88,7 @@ def get_carte_vigilance(self) -> dict: return req.json() - def get_phenomenon(self) -> Tuple[pd.DataFrame, pd.DataFrame]: + def get_phenomenon(self) -> tuple[pd.DataFrame, pd.DataFrame]: """ get risk prediction by phenomenon and by domain Returns: