From 1ed82d3f3655ed6e9d0248bc800c47ee670919b4 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:24:21 -0500 Subject: [PATCH 1/6] fix matplotlib call Signed-off-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGELOG.rst | 1 + src/ravenpy/utilities/graphs.py | 11 +++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 466705af..54e24b41 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,7 @@ v0.17.0 (unreleased) -------------------- * Updated the cookiecutter template to the latest commit and synchronized dependencies between PyPI and Anaconda recipes. (PR #427). +* Updated `ts_fit_graph` logic for `matplotlib` >= 3.10.0 compatibility. v0.16.1 (2024-12-05) -------------------- diff --git a/src/ravenpy/utilities/graphs.py b/src/ravenpy/utilities/graphs.py index 9fcadb0a..82909f94 100644 --- a/src/ravenpy/utilities/graphs.py +++ b/src/ravenpy/utilities/graphs.py @@ -330,7 +330,7 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi fig, axes = plt.subplots(n, figsize=(10, 6), squeeze=False) if params.isnull().any(): - raise ValueError("Null values in `params`.") + raise ValueError("Null values found in `params`.") for i in range(n): ax = axes.flat[i] @@ -343,14 +343,16 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi t, alpha=0.5, density=True, + edgecolor="grey", bins="auto", label="__nolabel__", ) ax2.hist( t, + alpha=0.5, bins=bins, - facecolor=(1, 1, 1, 0.01), - edgecolor="gray", + facecolor=(1, 1, 1), + edgecolor="grey", linewidth=1, ) @@ -362,7 +364,8 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi pdf = dc.pdf(q) ps = ", ".join([f"{x:.1f}" for x in p.values]) - ax.plot(q, pdf, "-", label="{}({})".format(params.attrs["scipy_dist"], ps)) + ax.plot(q, pdf, "-", label=f"{params.attrs['scipy_dist']}({ps})") + ax.set_zorder(2.5) # Labels ax.set_xlabel(f"{ts.long_name} (${units2pint(ts.units):~P}$)") From 827cc5abdbac36345d0e663fe20a4eed611794b3 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:48:56 -0500 Subject: [PATCH 2/6] update CHANGELOG.rst Signed-off-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 54e24b41..f02bcdf9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,7 +6,7 @@ v0.17.0 (unreleased) -------------------- * Updated the cookiecutter template to the latest commit and synchronized dependencies between PyPI and Anaconda recipes. (PR #427). -* Updated `ts_fit_graph` logic for `matplotlib` >= 3.10.0 compatibility. +* Updated `ts_fit_graph` logic for `matplotlib` >= 3.10.0 compatibility. (PR #434). v0.16.1 (2024-12-05) -------------------- From ecfc3a7292fa7caeb3ffe02deddf895c99bf70bd Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:58:43 -0500 Subject: [PATCH 3/6] fix call Signed-off-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- src/ravenpy/utilities/graphs.py | 1 - tests/test_graphs.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/ravenpy/utilities/graphs.py b/src/ravenpy/utilities/graphs.py index 82909f94..2378b72e 100644 --- a/src/ravenpy/utilities/graphs.py +++ b/src/ravenpy/utilities/graphs.py @@ -351,7 +351,6 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi t, alpha=0.5, bins=bins, - facecolor=(1, 1, 1), edgecolor="grey", linewidth=1, ) diff --git a/tests/test_graphs.py b/tests/test_graphs.py index aa9186dd..158af224 100644 --- a/tests/test_graphs.py +++ b/tests/test_graphs.py @@ -1,7 +1,7 @@ from shutil import copyfile import numpy as np -import xarray as xr +from xarray import open_dataset from xclim import set_options from xclim.indicators.generic import fit, stats @@ -17,7 +17,7 @@ def test_ts_fit_graph(self, get_local_testdata, tmp_path): copyfile(raven_hydrograph, file) - with xr.open_dataset(file) as ds: + with open_dataset(file) as ds: ts = stats(ds.q_sim, op="max", freq="ME") with set_options(check_missing="skip"): p = fit(ts) From 930acec727d3aa4ad474a64b2393b605327181fa Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:45:46 -0500 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: David Huard --- src/ravenpy/utilities/graphs.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/ravenpy/utilities/graphs.py b/src/ravenpy/utilities/graphs.py index 2378b72e..339b2be6 100644 --- a/src/ravenpy/utilities/graphs.py +++ b/src/ravenpy/utilities/graphs.py @@ -343,13 +343,12 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi t, alpha=0.5, density=True, - edgecolor="grey", bins="auto", label="__nolabel__", ) ax2.hist( t, - alpha=0.5, + facecolor="none", bins=bins, edgecolor="grey", linewidth=1, @@ -364,7 +363,6 @@ def ts_fit_graph(ts: xr.DataArray, params: xr.DataArray) -> matplotlib.pyplot.Fi ps = ", ".join([f"{x:.1f}" for x in p.values]) ax.plot(q, pdf, "-", label=f"{params.attrs['scipy_dist']}({ps})") - ax.set_zorder(2.5) # Labels ax.set_xlabel(f"{ts.long_name} (${units2pint(ts.units):~P}$)") From 7b0c69676ea7b138f19d981e9ac75853bf20d56f Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 8 Jan 2025 11:12:12 -0500 Subject: [PATCH 5/6] pin pygments temporarily Signed-off-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- environment-rtd.yml | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/environment-rtd.yml b/environment-rtd.yml index 9b6ff3ed..2fe24f24 100644 --- a/environment-rtd.yml +++ b/environment-rtd.yml @@ -25,7 +25,7 @@ dependencies: - notebook - pandoc - pydantic >=2.0 - - pygments + - pygments <2.19 # FIXME: Newest pygments breaks sphinx-codeautolink. See: https://github.com/felix-hilden/sphinx-codeautolink/issues/153 - salib - seaborn - sphinx >=7.0.0 diff --git a/pyproject.toml b/pyproject.toml index 3f79e053..615ddeba 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -114,7 +114,7 @@ docs = [ "myst_nb", "nbsphinx", "numpydoc >=1.8.0", - "pygments", + "pygments <2.19", # FIXME: Newest pygments breaks sphinx-codeautolink. See: https://github.com/felix-hilden/sphinx-codeautolink/issues/153 "pymetalink >=6.5.2", "salib", "s3fs", From b31be79a97e05c3eaca1f0eb836e458642699910 Mon Sep 17 00:00:00 2001 From: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> Date: Wed, 8 Jan 2025 14:59:32 -0500 Subject: [PATCH 6/6] update CHANGELOG.rst Signed-off-by: Trevor James Smith <10819524+Zeitsperre@users.noreply.github.com> --- CHANGELOG.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f02bcdf9..7da980c7 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,8 +5,9 @@ Changelog v0.17.0 (unreleased) -------------------- -* Updated the cookiecutter template to the latest commit and synchronized dependencies between PyPI and Anaconda recipes. (PR #427). -* Updated `ts_fit_graph` logic for `matplotlib` >= 3.10.0 compatibility. (PR #434). +* Updated the cookiecutter template to the latest commit and synchronized dependencies between PyPI and Anaconda recipes. (PR #427) +* Updated `ts_fit_graph` logic for `matplotlib` >= 3.10.0 compatibility. (PR #434) +* Temporarily pinned `pygments` below v2.19 due to a breaking change affecting `sphinx-codeautolink`. (PR #434) v0.16.1 (2024-12-05) --------------------