Skip to content

Commit

Permalink
remove 3.9 as supported version (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
nocollier authored Jan 24, 2025
1 parent e2d377f commit e07a023
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 49 deletions.
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,3 @@ repos:
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/numpy/numpydoc
rev: v1.7.0
hooks:
- id: numpydoc-validation
3 changes: 1 addition & 2 deletions ilamb3/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

from abc import ABC, abstractmethod
from typing import Union

import pandas as pd
import xarray as xr
Expand All @@ -21,7 +20,7 @@ class ILAMBAnalysis(ABC):
"""

@abstractmethod
def required_variables(self) -> Union[list[str], dict[str, list[str]]]:
def required_variables(self) -> list[str] | dict[str, list[str]]:
"""
Return the variables used in this analysis.
Expand Down
6 changes: 3 additions & 3 deletions ilamb3/analysis/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

import warnings
from typing import Literal, Union
from typing import Literal

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -56,11 +56,11 @@ def __call__(
ref: xr.Dataset,
com: xr.Dataset,
method: Literal["Collier2018", "RegionalQuantiles"] = "Collier2018",
regions: list[Union[str, None]] = [None],
regions: list[str | None] = [None],
use_uncertainty: bool = True,
spatial_sum: bool = False,
mass_weighting: bool = False,
quantile_dbase: Union[pd.DataFrame, None] = None,
quantile_dbase: pd.DataFrame | None = None,
quantile_threshold: int = 70,
) -> tuple[pd.DataFrame, xr.Dataset, xr.Dataset]:
"""
Expand Down
4 changes: 1 addition & 3 deletions ilamb3/analysis/nbp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
ILAMBAnalysis : The abstract base class from which this derives.
"""

from typing import Union

import numpy as np
import pandas as pd
import xarray as xr
Expand Down Expand Up @@ -47,7 +45,7 @@ def required_variables(self) -> list[str]:
return ["nbp"]

def __call__(
self, ref: xr.Dataset, com: xr.Dataset, evaluation_year: Union[int, None] = None
self, ref: xr.Dataset, com: xr.Dataset, evaluation_year: int | None = None
) -> tuple[pd.DataFrame, xr.Dataset, xr.Dataset]:
"""
Apply the ILAMB bias methodology on the given datasets.
Expand Down
2 changes: 1 addition & 1 deletion ilamb3/analysis/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def __call__(
self,
ref: xr.Dataset,
com: xr.Dataset,
regions: list[Union[str, None]] = [None],
regions: list[str | None] = [None],
) -> tuple[pd.DataFrame, xr.Dataset, xr.Dataset]:
"""
Apply the ILAMB relationship methodology on the given datasets.
Expand Down
8 changes: 3 additions & 5 deletions ilamb3/compare.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Functions for preparing datasets for comparison."""

from typing import Union

import numpy as np
import xarray as xr

Expand Down Expand Up @@ -94,8 +92,8 @@ def is_spatially_aligned(dsa: xr.Dataset, dsb: xr.Dataset) -> bool:
def pick_grid_aligned(
ref0: xr.Dataset,
com0: xr.Dataset,
ref: Union[xr.Dataset, None] = None,
com: Union[xr.Dataset, None] = None,
ref: xr.Dataset | None = None,
com: xr.Dataset | None = None,
) -> tuple[xr.Dataset, xr.Dataset]:
"""Return a reference and comparison dataset that is spatially grid-aligned.
Expand Down Expand Up @@ -292,5 +290,5 @@ def _populate_renames(ds):
return out

for arg in args:
assert isinstance(arg, (xr.DataArray, xr.Dataset))
assert isinstance(arg, xr.DataArray | xr.Dataset)
return [arg.rename(_populate_renames(arg)) for arg in args]
38 changes: 19 additions & 19 deletions ilamb3/dataset.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Convenience functions which operate on datasets."""

from typing import Any, Literal, Union
from typing import Any, Literal

import numpy as np
import xarray as xr
Expand All @@ -10,7 +10,7 @@


def get_dim_name(
dset: Union[xr.Dataset, xr.DataArray],
dset: xr.Dataset | xr.DataArray,
dim: Literal["time", "lat", "lon", "depth", "site"],
) -> str:
"""
Expand Down Expand Up @@ -70,7 +70,7 @@ def get_dim_name(


def get_coord_name(
dset: Union[xr.Dataset, xr.DataArray],
dset: xr.Dataset | xr.DataArray,
coord: Literal["lat", "lon"],
) -> str:
"""
Expand Down Expand Up @@ -163,7 +163,7 @@ def is_site(da: xr.DataArray) -> bool:


def get_time_extent(
dset: Union[xr.Dataset, xr.DataArray]
dset: xr.Dataset | xr.DataArray,
) -> tuple[xr.DataArray, xr.DataArray]:
"""
Return the time extent of the dataset/dataarray.
Expand All @@ -190,7 +190,7 @@ def get_time_extent(
return time.min(), time.max()


def compute_time_measures(dset: Union[xr.Dataset, xr.DataArray]) -> xr.DataArray:
def compute_time_measures(dset: xr.Dataset | xr.DataArray) -> xr.DataArray:
"""
Return the length of each time interval.
Expand Down Expand Up @@ -236,7 +236,7 @@ def _measure1d(time): # numpydoc ignore=GL08
return measure


def compute_cell_measures(dset: Union[xr.Dataset, xr.DataArray]) -> xr.DataArray:
def compute_cell_measures(dset: xr.Dataset | xr.DataArray) -> xr.DataArray:
"""
Return the area of each spatial cell.
Expand Down Expand Up @@ -366,8 +366,8 @@ def coarsen_dataset(dset: xr.Dataset, res: float = 0.5) -> xr.Dataset:


def integrate_time(
dset: Union[xr.Dataset, xr.DataArray],
varname: Union[str, None] = None,
dset: xr.Dataset | xr.DataArray,
varname: str | None = None,
mean: bool = False,
) -> xr.DataArray:
"""
Expand Down Expand Up @@ -418,8 +418,8 @@ def integrate_time(


def accumulate_time(
dset: Union[xr.Dataset, xr.DataArray],
varname: Union[str, None] = None,
dset: xr.Dataset | xr.DataArray,
varname: str | None = None,
) -> xr.DataArray:
"""
Return the time accumulation of the dataset.
Expand Down Expand Up @@ -456,7 +456,7 @@ def accumulate_time(


def std_time(
dset: Union[xr.Dataset, xr.DataArray], varname: Union[str, None] = None
dset: xr.Dataset | xr.DataArray, varname: str | None = None
) -> xr.DataArray:
"""
Return the standard deviation of a variable in time.
Expand Down Expand Up @@ -489,11 +489,11 @@ def std_time(


def integrate_space(
dset: Union[xr.DataArray, xr.Dataset],
dset: xr.DataArray | xr.Dataset,
varname: str,
region: Union[None, str] = None,
region: None | str = None,
mean: bool = False,
weight: Union[xr.DataArray, None] = None,
weight: xr.DataArray | None = None,
) -> xr.DataArray:
"""
Return the space integral or mean of the dataset.
Expand Down Expand Up @@ -625,8 +625,8 @@ def _get_interval(dset, dim, value, side): # numpydoc ignore=GL08


def integrate_depth(
dset: Union[xr.Dataset, xr.DataArray],
varname: Union[str, None] = None,
dset: xr.Dataset | xr.DataArray,
varname: str | None = None,
mean: bool = False,
) -> xr.DataArray:
"""
Expand Down Expand Up @@ -704,10 +704,10 @@ def scale_by_water_density(da: xr.DataArray, target: str) -> xr.DataArray:


def convert(
dset: Union[xr.Dataset, xr.DataArray],
dset: xr.Dataset | xr.DataArray,
unit: str,
varname: Union[str, None] = None,
) -> Union[xr.Dataset, xr.DataArray]:
varname: str | None = None,
) -> xr.Dataset | xr.DataArray:
"""
Convert the units of the dataarray.
Expand Down
14 changes: 7 additions & 7 deletions ilamb3/regions.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Region definitions for use in the ILAMB system."""

import os
from typing import Literal, Union
from typing import Literal

import numpy as np
import xarray as xr


def get_dim_name(
dset: Union[xr.Dataset, xr.DataArray], dim: Literal["time", "lat", "lon"]
dset: xr.Dataset | xr.DataArray, dim: Literal["time", "lat", "lon"]
) -> str:
"""Return the name of the `dim` dimension from the dataset.
Expand Down Expand Up @@ -40,7 +40,7 @@ def get_dim_name(


def restrict_to_bbox(
var: Union[xr.Dataset, xr.DataArray],
var: xr.Dataset | xr.DataArray,
lat_name: str,
lon_name: str,
lat0: float,
Expand Down Expand Up @@ -113,7 +113,7 @@ def add_latlon_bounds(
Regions._regions[label] = [rtype, name, lats, lons]
Regions._sources[label] = source

def add_netcdf(self, netcdf: Union[str, xr.Dataset]) -> list[str]:
def add_netcdf(self, netcdf: str | xr.Dataset) -> list[str]:
"""Add regions found in a netCDF file or dataset.
Region formatting guidelines can be found
Expand Down Expand Up @@ -173,9 +173,9 @@ def get_source(self, label: str):

def restrict_to_region(
self,
var: Union[xr.Dataset, xr.DataArray],
label: Union[str, None],
) -> Union[xr.Dataset, xr.DataArray]:
var: xr.Dataset | xr.DataArray,
label: str | None,
) -> xr.Dataset | xr.DataArray:
"""Given the region label and a variable, return a mask."""
if label is None:
return var
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ classifiers = [
"Intended Audience :: Science/Research",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Topic :: Scientific/Engineering",
]
description = "Earth system model benchmarking"
Expand Down Expand Up @@ -82,9 +82,10 @@ exclude_lines = ["pragma: no cover"]

[tool.ruff]
extend-exclude = [
"doc",
"docs",
]
target-version = "py39"
target-version = "py310"
[tool.ruff.lint]
ignore = [
"E402",
"E501",
Expand All @@ -99,7 +100,7 @@ select = [
"UP", # Pyupgrade
]

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["ilamb3"]

[tool.numpydoc_validation]
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e07a023

Please sign in to comment.