Skip to content

Commit

Permalink
Update to raven-hydro v0.3.1 (RHF 3.8.1), drop Python3.8 conventions,…
Browse files Browse the repository at this point in the history
… address warnings (#378)

## Changes

* Updates the `raven-hydro` package to v0.3.1 (RavenHydroFramework
v3.8.1)
* Synchronizes several dependencies between `pyproject.toml`,
`environment*.yml`, and `tox.ini`
* Drops the code formatting conventions for Python3.8
* Pins `numpy` below v2.0
* Addresses a bunch of small warnings in the `pytest` output

## Other information

This new build of `raven-hydro` will install on macOS systems using
x86_64 or ARM64 architectures, **but it does not seem to work for some
reason** (FYI @julemai; see:
CSHS-CWRA/RavenHydroFramework#35).
  • Loading branch information
Zeitsperre authored Jun 20, 2024
2 parents 731a6cb + 8b47515 commit cde004d
Show file tree
Hide file tree
Showing 45 changed files with 222 additions and 167 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
rev: v3.15.2
hooks:
- id: pyupgrade
args: [ '--py38-plus' ]
args: [ '--py39-plus' ]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
Expand Down Expand Up @@ -49,7 +49,7 @@ repos:
rev: 1.8.5
hooks:
- id: nbqa-pyupgrade
args: [ '--py38-plus' ]
args: [ '--py39-plus' ]
additional_dependencies: [ 'pyupgrade==3.15.2' ]
- id: nbqa-black
additional_dependencies: [ 'black==24.4.2' ]
Expand Down
10 changes: 9 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,16 @@ History

0.15.0 (unreleased)
-------------------
* Pinned `pint` below version 0.24 due to a breaking change in their API. (PR #375)
* Pinned `numpy` below v2.0.0 due to a breaking change in their API. (PR #378)
* Update `raven-hydro` to v0.3.1 and `RavenHydroFramework` to v3.8.1. (PR #378)
* Fixed bug in `Config.duplicate` dating from the switch to Pydantic V2 in 0.13 (PR #367)
* Pinned `pint` below version 0.24 due to a breaking change in their API.

Internal changes
^^^^^^^^^^^^^^^^
* Synchronize several dependencies between `pyproject.toml`, `environment*.yml`, and `tox.ini`. (PR #378)
* Drop the code formatting conventions for Python3.8, extend to Python3.11 and Python3.12. (PR #378)
* Addresses a bunch of small warnings in the pytest output. (PR #378)

0.14.1 (2024-05-07)
-------------------
Expand Down
9 changes: 5 additions & 4 deletions environment-rtd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ channels:
- defaults
dependencies:
- python >=3.9,<3.10 # fixed to reduce solver time
- raven-hydro >=0.2.4,<1.0
- raven-hydro >=0.3.1,<1.0
- autodoc-pydantic
- click
- click >=8.0.0
# - clisops # mocked
- gdal
- gdal >=3.1
# Needed for notebooks/HydroShare_integration.ipynb
# See: https://github.com/CSHS-CWRA/RavenPy/pull/326
# - "hsclient",
Expand All @@ -20,13 +20,14 @@ dependencies:
- jupytext
- nbsphinx
# - netCDF4 # mocked
- numpy <2.0.0
- notebook
- pandoc
- pydantic >=2.0
- pygments
- salib
- seaborn
- sphinx
- sphinx >=7.0.0
- sphinx-autoapi
- sphinx-click
- sphinx-codeautolink
Expand Down
26 changes: 14 additions & 12 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ channels:
- defaults
dependencies:
- python >=3.9,<3.13
- raven-hydro >=0.2.4,<1.0
- raven-hydro >=0.3.1,<1.0
- libgcc # for mixing raven-hydro from PyPI with conda environments
- affine
- black >=24.2.0
- black >=24.4.2
- bump2version >=1.0.1
- cftime
- cf_xarray
- click
- click >=8.0.0
- climpred >=2.4.0
- coveralls >=4.0.0
- coverage >=7.5.0
- dask
- fiona >=1.9
- flake8 >=7.0.0
- flit
- flit >=3.9.0
- gdal >=3.1
- geopandas >=0.14.0
- h5netcdf
Expand All @@ -25,22 +27,22 @@ dependencies:
- hvplot
- isort >=5.13.2
- lxml
- matplotlib
- matplotlib-base
- mypy
- netcdf4
- numpy
- netcdf4 <=1.6.5
- numpy <2.0.0
- owslib >=0.29.1
- pandas >=2.2.0
- pint >=0.20,<0.24
- platformdirs
- pre-commit
- pre-commit >=3.5.0
- pydantic >=2.0
- pydap
- pymbolic
- pyogrio <0.8.0 # pyogrio 0.8.0 is not yet compatible with geopandas
- pyproj >=3.0
- pytest
- pytest-cov
- pytest >=7.0.0
- pytest-cov >=5.0.0
- pytest-xdist >=3.2.0
- rasterio
- requests
Expand All @@ -49,10 +51,10 @@ dependencies:
- shapely
- spotpy
- statsmodels
- tox >=4.5
- tox >=4.15.1
- typing_extensions
- watchdog
- xarray >=2023.11.0
- xclim >=0.48.2
- xclim >=0.48.2 # xclim 0.50.0 is not yet available on conda-forge
- xesmf
- xskillscore
38 changes: 20 additions & 18 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[build-system]
requires = ["flit_core >=3.8,<4"]
requires = ["flit_core >=3.9,<4"]
build-backend = "flit_core.buildapi"

[project]
Expand Down Expand Up @@ -38,50 +38,51 @@ dependencies = [
"cftime",
# cf-xarray is differently named on conda-forge
"cf-xarray",
"click >=8.0.0",
"climpred >=2.4.0",
"dask",
"haversine",
"h5netcdf",
"matplotlib",
"netCDF4",
"numpy",
"netCDF4 <=1.6.5",
"numpy <2.0.0",
"owslib >=0.29.1",
"pandas >=2.2.0",
"pint >=0.20,<0.24",
"platformdirs",
"pydantic >=2.0",
"pydap",
"pymbolic",
"raven-hydro >=0.2.4,<1.0",
"raven-hydro >=0.3.1,<1.0",
"requests",
"scipy",
"spotpy",
"statsmodels",
"typing-extensions",
"xarray >=2023.11.0",
"xclim >=0.48.2",
"xclim >=0.50.0",
"xskillscore"
]

[project.optional-dependencies]
dev = [
"black >=24.2.0",
"black >=24.4.2",
"bump2version",
"coverage",
"coveralls",
"coverage >=7.5.0",
"coveralls >=4.0.0",
"filelock",
"flake8 >=7.0.0",
"flit",
"flit >=3.9.0",
"holoviews",
"hvplot",
"isort >=5.13.2",
"mypy",
"pre-commit",
"pytest",
"pytest-cov",
"pre-commit >=3.5.0",
"pytest >=7.0.0",
"pytest-cov >=5.0.0",
"pytest-xdist >=3.2.0",
"setuptools >=68.0",
"tox >=4.5",
"tox >=4.15.1",
"watchdog",
"wheel >=0.42.0"
]
Expand Down Expand Up @@ -111,7 +112,7 @@ docs = [
"pymetalink",
"salib",
"s3fs",
"sphinx",
"sphinx >=7.0.0",
"sphinx-click",
"sphinx-codeautolink",
"sphinx-copybutton",
Expand All @@ -122,7 +123,7 @@ gis = [
"affine",
"fiona >=1.9",
"geopandas >=0.14.0",
"gdal",
"gdal >=3.1",
"lxml",
"pyogrio <0.8.0", # pyogrio 0.8.0 is not compatible with geopandas
"pyproj >=3.0.0",
Expand All @@ -146,9 +147,10 @@ ravenpy = "ravenpy.cli:main"

[tool.black]
target-version = [
"py38",
"py39",
"py310"
"py310",
"py311",
"py312"
]

[tool.coverage.run]
Expand Down Expand Up @@ -190,7 +192,7 @@ exclude = [

[tool.isort]
profile = "black"
py_version = 38
py_version = 39
append_only = true

[tool.mypy]
Expand Down
5 changes: 3 additions & 2 deletions ravenpy/config/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import typing
from collections.abc import Sequence
from enum import Enum
from textwrap import dedent, indent
from typing import Any, Dict, Optional, Sequence, Tuple, Union
from typing import Any, Dict, Optional, Tuple, Union

from pydantic import BaseModel, ConfigDict, Field, RootModel, model_validator
from pymbolic.primitives import Expression, Variable
Expand Down Expand Up @@ -140,7 +141,7 @@ def _template(self):
def __str__(self):
return self.to_rv()

def __subcommands__(self) -> Tuple[Dict[str, str], list]:
def __subcommands__(self) -> tuple[dict[str, str], list]:
"""Return dictionary of class attributes that are Raven models."""
cmds = {}
recs = []
Expand Down
22 changes: 11 additions & 11 deletions ravenpy/config/commands.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import datetime as dt
import itertools
import re
from collections.abc import Sequence
from pathlib import Path
from textwrap import dedent, indent
from typing import (
Annotated,
Any,
Dict,
Literal,
Optional,
Sequence,
Tuple,
Union,
get_args,
Expand All @@ -30,7 +31,6 @@
field_validator,
model_validator,
)
from typing_extensions import Annotated

from ..config import options
from .base import (
Expand Down Expand Up @@ -62,7 +62,7 @@

INDENT = " " * 4
VALUE_PADDING = 10
T12 = Tuple[
T12 = tuple[
float,
float,
float,
Expand Down Expand Up @@ -424,8 +424,8 @@ class ChannelProfile(FlatCommand):

name: str = "chn_XXX"
bed_slope: float = 0
survey_points: Tuple[Tuple[float, float], ...] = ()
roughness_zones: Tuple[Tuple[float, float], ...] = ()
survey_points: tuple[tuple[float, float], ...] = ()
roughness_zones: tuple[tuple[float, float], ...] = ()

def to_rv(self):
template = """
Expand Down Expand Up @@ -464,7 +464,7 @@ class GridWeights(Command):
number_grid_cells: int = Field(1, alias="NumberGridCells")

class GWRecord(RootRecord):
root: Tuple[int, int, float] = (1, 0, 1.0)
root: tuple[int, int, float] = (1, 0, 1.0)

def __iter__(self):
return iter(self.root)
Expand Down Expand Up @@ -720,9 +720,9 @@ def from_nc(
fn: Union[str, Path, Sequence[Path]],
data_type: Optional[Sequence[str]] = None,
station_idx: int = 1,
alt_names: Optional[Dict[str, str]] = None,
alt_names: Optional[dict[str, str]] = None,
mon_ave: bool = False,
data_kwds: Optional[Dict[str, Any]] = None,
data_kwds: Optional[dict[str, Any]] = None,
engine: str = "h5netcdf",
**kwds,
) -> "Gauge":
Expand Down Expand Up @@ -843,7 +843,7 @@ def from_nc(cls, fn, station_idx: int = 1, alt_names=(), engine="h5netcdf", **kw

class HRUState(Record):
hru_id: int = 1
data: Dict[str, Sym] = Field(default_factory=dict)
data: dict[str, Sym] = Field(default_factory=dict)

def __str__(self):
return ",".join(map(str, (self.hru_id,) + tuple(self.data.values())))
Expand Down Expand Up @@ -972,7 +972,7 @@ def parse(cls, sol):
class SoilClasses(ListCommand):
class SoilClass(Record):
name: str
mineral: Optional[Tuple[float, float, float]] = None
mineral: Optional[tuple[float, float, float]] = None
organic: Optional[float] = None

@field_validator("mineral")
Expand All @@ -986,7 +986,7 @@ def validate_mineral(cls, v):

@field_validator("mineral")
@classmethod
def validate_mineral_pct(cls, v: Tuple):
def validate_mineral_pct(cls, v: tuple):
if v is not None:
for x in v:
assert (x >= 0) and (x <= 1), "Value should be in [0,1]."
Expand Down
7 changes: 4 additions & 3 deletions ravenpy/config/emulators/blended.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from collections.abc import Sequence
from dataclasses import field, make_dataclass
from typing import Dict, Sequence, Union
from typing import Dict, Union

from pydantic import Field, field_validator
from pydantic.dataclasses import dataclass
Expand Down Expand Up @@ -73,7 +74,7 @@ class Blended(Config):
],
alias="HRUs",
)
netcdf_attribute: Dict[str, str] = {"model_id": "Blended"}
netcdf_attribute: dict[str, str] = {"model_id": "Blended"}
sub_basins: rc.SubBasins = Field([rc.SubBasin()], alias="SubBasins")
write_netcdf_format: bool = Field(True, alias="WriteNetcdfFormat")
time_step: Union[float, str] = Field(1.0, alias="TimeStep")
Expand Down Expand Up @@ -213,7 +214,7 @@ class Blended(Config):
alias="SoilProfiles",
)

global_parameter: Dict = Field(
global_parameter: dict = Field(
{
"SNOW_SWI_MIN": P.X13,
"SNOW_SWI_MAX": P.X14,
Expand Down
Loading

0 comments on commit cde004d

Please sign in to comment.