From 6032244d9514b166f9883109eabfb6651c452872 Mon Sep 17 00:00:00 2001 From: Fridolin Glatter <83776373+glatterf42@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:22:05 +0100 Subject: [PATCH] Replace resolved numpy workaround with dask workaround (#245) * Add default of same type as choicelist for np.select() * Install pinned dask version only for specific runs --- .github/workflows/pytest.yaml | 22 ++++++++++++++----- message_ix_models/model/water/data/demands.py | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index a43315d2d6..8ca222bb14 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -46,23 +46,29 @@ jobs: - version: v3.4.0 python-version: "3.11" extra-deps: '"dask < 2024.3.0" "genno < 1.25" "pandas < 2.0" "pytest == 8.0.0"' # + dask-dataframe: false - version: v3.5.0 python-version: "3.11" extra-deps: '"dask < 2024.3.0" "genno < 1.25" "pandas < 2.0" "pytest == 8.0.0"' # + dask-dataframe: false - version: v3.6.0 python-version: "3.11" extra-deps: '"dask < 2024.3.0" "genno < 1.25" "pandas < 2.0" "pytest == 8.0.0"' # + dask-dataframe: false - version: v3.7.0 python-version: "3.11" - extra-deps: 'dask[dataframe] "genno < 1.25" "pytest == 8.0.0"' # + extra-deps: ' "genno < 1.25" "pytest == 8.0.0"' # + dask-dataframe: true # Latest released version - version: v3.8.0 python-version: "3.12" - extra-deps: 'dask[dataframe] "pytest == 8.0.0"' # + extra-deps: ' "pytest == 8.0.0"' # + dask-dataframe: true # Development version - version: main python-version: "3.12" - extra-deps: 'dask[dataframe]' # + extra-deps: '' # + dask-dataframe: true fail-fast: false @@ -109,9 +115,13 @@ jobs: pip install .[docs,tests] ${{ matrix.upstream.extra-deps }} - # TEMPORARY Work around hgrecco/pint#2007, unionai-oss/pandera#1685; - # see https://github.com/khaeru/genno/issues/140 - pip install "pint != 0.24.0" "numpy < 2" + + - name: Install specific dask versions as workaround + if: ${{ matrix.upstream.dask-dataframe }} + run: | + # TEMPORARY Work around dask v2024.11.0; + # see https://github.com/khaeru/genno/issues/149 + pip install "dask[dataframe] < 2024.11.0" - name: Configure local data path run: | diff --git a/message_ix_models/model/water/data/demands.py b/message_ix_models/model/water/data/demands.py index 856fdf611c..912398886b 100644 --- a/message_ix_models/model/water/data/demands.py +++ b/message_ix_models/model/water/data/demands.py @@ -644,7 +644,7 @@ def add_sectoral_demands(context: "Context") -> dict[str, pd.DataFrame]: ] # create a new column and use np.select to assign # values to it using our lists as arguments - h_act["commodity"] = np.select(conditions, values) + h_act["commodity"] = np.select(conditions, values, "Unknown commodity") h_act["value"] = h_act["value"].abs() hist_act = make_df(