From 8930af04832e584b2c8c43c457314cb0a0959bec Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 12 Apr 2024 16:38:28 +0100 Subject: [PATCH 01/62] add numpy 2 from conda-forge dev --- environment.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index f84372d197..df3f56a083 100644 --- a/environment.yml +++ b/environment.yml @@ -1,6 +1,7 @@ --- name: esmvaltool channels: + - conda-forge/label/dev - conda-forge - nodefaults @@ -28,7 +29,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy !=1.24.3 + - numpy==2.0.0rc1 # !=1.24.3 - packaging - pandas !=2.2.0,!=2.2.1 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From a3e0632e7cb3077f60af6d204728e22faec2881f Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 12 Apr 2024 16:38:50 +0100 Subject: [PATCH 02/62] temp remove PyPI numpy - add numpy 2 from conda-forge dev --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fc6cdb2678..8099fe2087 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ 'nc-time-axis', # needed by iris.plot 'nested-lookup', 'netCDF4', - 'numpy!=1.24.3', + # 'numpy!=1.24.3', # install 2.0.0rc1 from conda-forge/dev 'packaging', 'pandas!=2.2.0,!=2.2.1', # GH ESMValCore #2305 #2349 'pillow', From 233eb67383ab3f733ac8345949a5312109725524 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 12 Apr 2024 16:39:03 +0100 Subject: [PATCH 03/62] run a GA --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ce057f1ef5..9a82f69f80 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -21,6 +21,7 @@ on: push: branches: - main + - numpy2-dev # run the test only if the PR is to main # turn it on if required #pull_request: From 3687ea0528095e5430a356365d2dbed0b01fc5e1 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 12 Apr 2024 17:13:45 +0100 Subject: [PATCH 04/62] remove numpy from env --- environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index df3f56a083..df9470011e 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,6 @@ --- name: esmvaltool channels: - - conda-forge/label/dev - conda-forge - nodefaults @@ -29,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy==2.0.0rc1 # !=1.24.3 + # - numpy==2.0.0rc1 # !=1.24.3 - packaging - pandas !=2.2.0,!=2.2.1 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From bf8dff55d100b736565bc4c5e3da00f4a2def90a Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 12 Apr 2024 17:13:59 +0100 Subject: [PATCH 05/62] manually install numpy 2.0 --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9a82f69f80..e96693c714 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -59,6 +59,7 @@ jobs: - run: conda --version 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/conda_version.txt - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt + - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py39h8eeae49_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 29284bc830a56fa298bc1f4962707b2e878da649 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 15 Apr 2024 12:31:11 +0100 Subject: [PATCH 06/62] correct conda forge channel --- environment.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index df9470011e..ad4dd646e7 100644 --- a/environment.yml +++ b/environment.yml @@ -1,6 +1,7 @@ --- name: esmvaltool channels: + - conda-forge/label/numpy_dev - conda-forge - nodefaults @@ -28,7 +29,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - # - numpy==2.0.0rc1 # !=1.24.3 + - numpy==2.0.0rc1 # !=1.24.3 - packaging - pandas !=2.2.0,!=2.2.1 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From 23429bc549920ece69f1013d59559884fbfce565 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 15 Apr 2024 12:31:17 +0100 Subject: [PATCH 07/62] correct conda forge channel --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 8099fe2087..83ff6d06c7 100755 --- a/setup.py +++ b/setup.py @@ -45,7 +45,7 @@ 'nc-time-axis', # needed by iris.plot 'nested-lookup', 'netCDF4', - # 'numpy!=1.24.3', # install 2.0.0rc1 from conda-forge/dev + # 'numpy!=1.24.3', # install 2.0.0rc1 from conda-forge/label/numpy_dev 'packaging', 'pandas!=2.2.0,!=2.2.1', # GH ESMValCore #2305 #2349 'pillow', From 50910b425b58f2024270953bc979275a60482436 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 15 Apr 2024 12:31:37 +0100 Subject: [PATCH 08/62] do not install manually numpy, like a peasant --- .github/workflows/run-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index e96693c714..9a82f69f80 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -59,7 +59,6 @@ jobs: - run: conda --version 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/conda_version.txt - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt - - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py39h8eeae49_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 4d5d1ebcafe483c0509bfa710d4e02521ba2c687 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 15 Apr 2024 12:47:05 +0100 Subject: [PATCH 09/62] revert to manual installation --- .github/workflows/run-tests.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 9a82f69f80..e054e9370e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -59,6 +59,8 @@ jobs: - run: conda --version 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/conda_version.txt - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt + # install manually since conda installation results in conflicts; get Python 3.11 version + - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py311h97fb7c7_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 9fb584a45a4c7bf329a150feacbb27e4f5b1ac0c Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 15 Apr 2024 12:47:50 +0100 Subject: [PATCH 10/62] comment out numpy gubbins i environment yml --- environment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index ad4dd646e7..4980c8ded5 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,7 @@ --- name: esmvaltool channels: - - conda-forge/label/numpy_dev + # - conda-forge/label/numpy_dev - conda-forge - nodefaults @@ -29,7 +29,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy==2.0.0rc1 # !=1.24.3 + # - numpy==2.0.0rc1 # !=1.24.3 - packaging - pandas !=2.2.0,!=2.2.1 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From d36350a8b4fb4d7f8fd4303604a804b4cba544ea Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 27 May 2024 13:48:20 +0100 Subject: [PATCH 11/62] deactivate direct download --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index ccd4932c58..538cc3a403 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -60,7 +60,7 @@ jobs: - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt # install manually since conda installation results in conflicts; get Python 3.11 version - - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py311h97fb7c7_0.conda + # - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py311h97fb7c7_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 5dfa45aaa6f665f72d202253c30acac37863f35e Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 27 May 2024 13:51:03 +0100 Subject: [PATCH 12/62] use direct download again --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index c7b56febd6..0bd1e55a0d 100644 --- a/environment.yml +++ b/environment.yml @@ -28,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy==2.0.0rc2 + # - numpy==2.0.0rc2 - packaging - pandas !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From baedee8d64144e6d2757abb14dafd8266ebb2b80 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 27 May 2024 13:53:41 +0100 Subject: [PATCH 13/62] use direct download again --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 538cc3a403..c3f6b20b8b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -60,7 +60,7 @@ jobs: - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt # install manually since conda installation results in conflicts; get Python 3.11 version - # - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc1/download/linux-64/numpy-2.0.0rc1-py311h97fb7c7_0.conda + - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc2/download/linux-64/numpy-2.0.0rc2-py311h1461c94_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From ccb8f2f023dcef273534f1f2cbd1350927bd42fe Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 17 Jun 2024 13:34:32 +0100 Subject: [PATCH 14/62] use conda forge package --- environment.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/environment.yml b/environment.yml index 4a403a065b..b08e8f2af4 100644 --- a/environment.yml +++ b/environment.yml @@ -1,7 +1,6 @@ --- name: esmvaltool channels: - # - conda-forge/label/numpy_dev - conda-forge - nodefaults @@ -29,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - # - numpy==2.0.0rc2 + - numpy >=2.0.0 - packaging - pandas !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From 882c1cddb1873696add2dd5249a506c54fdaaff7 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 17 Jun 2024 13:34:48 +0100 Subject: [PATCH 15/62] dont install from conda package --- .github/workflows/run-tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 4a7f93a3e6..eebfb91ba6 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -61,7 +61,7 @@ jobs: - run: conda list - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt # install manually since conda installation results in conflicts; get Python 3.11 version - - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc2/download/linux-64/numpy-2.0.0rc2-py311h1461c94_0.conda + # - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc2/download/linux-64/numpy-2.0.0rc2-py311h1461c94_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 6d9cda55cfd2ef154bb3c19ced7d7fdbc20ec6b3 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 17 Jun 2024 13:35:55 +0100 Subject: [PATCH 16/62] restore numpy dep --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7c1353aaaf..76e97a9658 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ 'nc-time-axis', # needed by iris.plot 'nested-lookup', 'netCDF4', - # 'numpy!=1.24.3', # install 2.0.0rc2 from conda-forge/label/numpy_dev + 'numpy!=1.24.3', 'packaging', 'pandas!=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc 'pillow', From e3e2e2560aed257061215793f9c6d19a517c050e Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 17 Jun 2024 13:41:57 +0100 Subject: [PATCH 17/62] completeley remove line that installed numpy2 from anaconda package --- .github/workflows/run-tests.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index eebfb91ba6..2e1b0d3c42 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -60,8 +60,6 @@ jobs: - run: python -V 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/python_version.txt - run: conda list - run: pip install -e .[develop] 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/install.txt - # install manually since conda installation results in conflicts; get Python 3.11 version - # - run: mamba install https://anaconda.org/conda-forge/numpy/2.0.0rc2/download/linux-64/numpy-2.0.0rc2-py311h1461c94_0.conda - run: conda list - run: flake8 - run: pytest -n 2 -m "not installation" 2>&1 | tee test_linux_artifacts_python_${{ matrix.python-version }}/test_report.txt From 30c99e56d992974ca3a48b498948456f42b636f7 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 14:07:51 +0100 Subject: [PATCH 18/62] unpin pandas --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index b08e8f2af4..ecbb605fb6 100644 --- a/environment.yml +++ b/environment.yml @@ -30,7 +30,7 @@ dependencies: - netcdf4 - numpy >=2.0.0 - packaging - - pandas !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 + - pandas # !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow - pip !=21.3 - prov From 98ee11600c8634c5e87b209fd00c8decc0062490 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 14:08:21 +0100 Subject: [PATCH 19/62] unpin pandas --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 76e97a9658..7c0ce1e45d 100755 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ 'netCDF4', 'numpy!=1.24.3', 'packaging', - 'pandas!=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc + 'pandas', # !=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc 'pillow', 'prov', 'psutil', From 0e2799be6b9d1fd77c6642a568a2989ee5d2a58a Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 15:43:14 +0100 Subject: [PATCH 20/62] release numpy to choose its path --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index ecbb605fb6..bd3147381a 100644 --- a/environment.yml +++ b/environment.yml @@ -28,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy >=2.0.0 + - numpy !=1.24.3 - packaging - pandas # !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From 03a46fa5913536bdf6ac77ce50abb38e9e52ac1e Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 15:54:13 +0100 Subject: [PATCH 21/62] replace np.NaN with np.nan --- esmvalcore/preprocessor/_derive/_shared.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_derive/_shared.py b/esmvalcore/preprocessor/_derive/_shared.py index e6d07011f1..c8d4585ae0 100644 --- a/esmvalcore/preprocessor/_derive/_shared.py +++ b/esmvalcore/preprocessor/_derive/_shared.py @@ -153,7 +153,7 @@ def _create_pressure_array(cube, ps_cube, top_limit): ps_4d_array = iris.util.broadcast_to_shape(ps_cube.data, shape, [0, 2, 3]) # Set pressure levels below the surface pressure to NaN - pressure_4d = np.where((ps_4d_array - p_4d_array) < 0, np.NaN, p_4d_array) + pressure_4d = np.where((ps_4d_array - p_4d_array) < 0, np.nan, p_4d_array) # Make top_limit last pressure level top_limit_array = np.full(ps_cube.shape, top_limit, dtype=np.float32) From af8944e3c6ded5c06b89654173a90d7a2dc3ae7a Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 15:54:23 +0100 Subject: [PATCH 22/62] replace np.NaN with np.nan --- tests/unit/preprocessor/_derive/test_shared.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/preprocessor/_derive/test_shared.py b/tests/unit/preprocessor/_derive/test_shared.py index 23b4ee9047..c92d10e368 100644 --- a/tests/unit/preprocessor/_derive/test_shared.py +++ b/tests/unit/preprocessor/_derive/test_shared.py @@ -135,7 +135,7 @@ def test_low_lev_below_surf_press(): """Test for lowest level below surface pressure.""" plev = 970 top_limit = 5 - col = np.array([np.NaN, 900, 800]) + col = np.array([np.nan, 900, 800]) col = np.insert(col, 0, plev) col = np.append(col, top_limit) result = np.array([0, 120, 845]) @@ -148,7 +148,7 @@ def test_low_lev_below_surf_press(): assert np.array_equal(_get_pressure_level_widths(col, air_pressure_axis=1), np.atleast_3d(result)) - col = np.array([np.NaN, np.NaN, 900, 800]) + col = np.array([np.nan, np.nan, 900, 800]) col = np.insert(col, 0, plev) col = np.append(col, top_limit) result = np.array([0, 0, 120, 845]) From 6a8fe23f61ad295f3d8ab191666a6dcee3952005 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 16:13:19 +0100 Subject: [PATCH 23/62] fix for new output of np.ogrid --- esmvalcore/preprocessor/_time.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_time.py b/esmvalcore/preprocessor/_time.py index d4dff4c1f9..d0431cf8d2 100644 --- a/esmvalcore/preprocessor/_time.py +++ b/esmvalcore/preprocessor/_time.py @@ -1559,7 +1559,9 @@ def _transform_to_lst_eager( """ # Apart from the time index, all other dimensions will stay the same; this # is ensured with np.ogrid - idx = np.ogrid[tuple(slice(0, d) for d in data.shape)] + # NOTE: in numpy 2.0 np.ogrid returns ndarray or tuple of ndarrays + # so item assignment can only be done after converting to a list + idx = list(np.ogrid[tuple(slice(0, d) for d in data.shape)]) time_index = broadcast_to_shape( time_index, data.shape, (time_dim, lon_dim) ) From e849a7332292627bbd1982177b1242389e91dc99 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 19 Jun 2024 16:44:48 +0100 Subject: [PATCH 24/62] add printout to test --- .../preprocessor/_compare_with_refs/test_compare_with_refs.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py index 7def9afe1b..f001e3334d 100644 --- a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py +++ b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py @@ -661,6 +661,7 @@ def test_distance_metric_fully_masked_data( assert out_cube.dtype == np.float64 expected_data = np.ma.masked_all(()) + print("out/in/metric", out_cube.data, expected_data, metric) assert_allclose(out_cube.data, expected_data) assert out_cube.var_name == var_name assert out_cube.long_name == long_name From 3ec3fe5da694db702e57b7decbdcf405c4e6e3f0 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 20 Jun 2024 13:53:12 +0100 Subject: [PATCH 25/62] explicitly cast Python int --- esmvalcore/preprocessor/_regrid_unstructured.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/esmvalcore/preprocessor/_regrid_unstructured.py b/esmvalcore/preprocessor/_regrid_unstructured.py index 6618c728c0..f4f3cae2fa 100644 --- a/esmvalcore/preprocessor/_regrid_unstructured.py +++ b/esmvalcore/preprocessor/_regrid_unstructured.py @@ -169,8 +169,11 @@ def _get_weights_and_idx( src_points_with_convex_hull = self._add_convex_hull_twice( src_points, hull.vertices ) - src_points_with_convex_hull[-2 * n_hull:-n_hull, 1] -= 360 - src_points_with_convex_hull[-n_hull:, 1] += 360 + # explicitly casting to int32 since without it, in Numpy 2.0 + # one gets OverflowError: Python integer 360 out of bounds for int8 + # see notes https://numpy.org/devdocs/numpy_2_0_migration_guide.html + src_points_with_convex_hull[-2 * n_hull:-n_hull, 1] -= np.int32(360) + src_points_with_convex_hull[-n_hull:, 1] += np.int32(360) # Actual weights calculation (weights, indices) = self._calculate_weights( From 26a52288d15a687981e1104f0570f5ea82a98253 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 20 Jun 2024 15:13:33 +0100 Subject: [PATCH 26/62] use vstack instead of simple array --- esmvalcore/preprocessor/_regrid_esmpy.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_regrid_esmpy.py b/esmvalcore/preprocessor/_regrid_esmpy.py index c7edfa829c..411735222e 100755 --- a/esmvalcore/preprocessor/_regrid_esmpy.py +++ b/esmvalcore/preprocessor/_regrid_esmpy.py @@ -243,7 +243,10 @@ def get_grid(esmpy_lat, esmpy_lon, num_peri_dims = 1 else: num_peri_dims = 0 - grid = esmpy.Grid(np.array(esmpy_lat.shape), + + # previous to numpy 2.0, a np.array(esmpy_lat.shape) was used + # numpy>=2.0 throws ValueError: matrix transpose with ndim<2 is undefined + grid = esmpy.Grid(np.vstack(esmpy_lat.shape), num_peri_dims=num_peri_dims, staggerloc=[esmpy.StaggerLoc.CENTER]) grid.get_coords(ESMF_LON)[...] = esmpy_lon From ecf68f8ebcfdf73da87f8136ff342a300a4141a5 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 20 Jun 2024 15:22:23 +0100 Subject: [PATCH 27/62] make list out of now tuple --- esmvalcore/preprocessor/_derive/co2s.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/esmvalcore/preprocessor/_derive/co2s.py b/esmvalcore/preprocessor/_derive/co2s.py index 052800f83a..91023ad2cd 100644 --- a/esmvalcore/preprocessor/_derive/co2s.py +++ b/esmvalcore/preprocessor/_derive/co2s.py @@ -15,6 +15,8 @@ def _get_first_unmasked_data(array, axis): indices = da.meshgrid( *[da.arange(array.shape[i]) for i in range(array.ndim) if i != axis], indexing='ij') + # numpy>=2.0 indices becomes a tuple + indices = list(indices) indices.insert(axis, indices_first_positive) first_unmasked_data = np.array(array)[tuple(indices)] return first_unmasked_data From c10ce96c7967ae751d49fa5ca284838ffa1f52ec Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 20 Jun 2024 16:19:56 +0100 Subject: [PATCH 28/62] explicit cast to numpy strings ffs --- tests/unit/preprocessor/_time/test_time.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/unit/preprocessor/_time/test_time.py b/tests/unit/preprocessor/_time/test_time.py index b478a97143..5331391a47 100644 --- a/tests/unit/preprocessor/_time/test_time.py +++ b/tests/unit/preprocessor/_time/test_time.py @@ -920,9 +920,12 @@ def test_season_not_available(self): name='clim_season', seasons=['JFMAMJ', 'JASOND'], ) + + # numpy>=2.0 these need to be explicitly cast to numpy strings + two_seasons = [np.str_('JASOND'), np.str_('JFMAMJ')] msg = ( "Seasons ('DJF', 'MAM', 'JJA', 'SON') do not match prior season " - "extraction ['JASOND', 'JFMAMJ']." + f"extraction {two_seasons}." ) with pytest.raises(ValueError, match=re.escape(msg)): seasonal_statistics(cube, 'mean') From f822bb84411b7fa0106f94b685a518975eceeef2 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 15:56:06 +0100 Subject: [PATCH 29/62] reqwite the distance stat with sqrt account for masks --- esmvalcore/preprocessor/_compare_with_refs.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_compare_with_refs.py b/esmvalcore/preprocessor/_compare_with_refs.py index 1634fc1752..dfe2bbf88e 100644 --- a/esmvalcore/preprocessor/_compare_with_refs.py +++ b/esmvalcore/preprocessor/_compare_with_refs.py @@ -451,7 +451,19 @@ def _calculate_rmse( weights = get_weights(cube, coords) if weighted else None squared_error = (cube.core_data() - reference.core_data())**2 npx = get_array_module(squared_error) - rmse = npx.sqrt(npx.ma.average(squared_error, axis=axis, weights=weights)) + + # need masked sqrt for numpy >=2.0 + # and dask.array.reductions.safe_sqrt for Dask + # otherwise results will be computed ignoring masks + if npx.__name__ == "dask.array": + da_squared_error = npx.ma.average(squared_error, + axis=axis, + weights=weights) + rmse = npx.reductions.safe_sqrt(da_squared_error) + else: + rmse = npx.ma.sqrt( + npx.ma.average(squared_error, axis=axis, weights=weights) + ) # Metadata metadata = CubeMetadata( From 061a4fbb6ae65bbfb7172207487bb5d594c32bb9 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 15:56:29 +0100 Subject: [PATCH 30/62] account for variations in rstol for numpy 2.0 --- .../_compare_with_refs/test_compare_with_refs.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py index f001e3334d..8ac57b2406 100644 --- a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py +++ b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py @@ -15,15 +15,15 @@ from tests import PreprocessorFile -def assert_allclose(array_1, array_2): +def assert_allclose(array_1, array_2, rtol=1e-7): """Assert that (masked) array 1 is close to (masked) array 2.""" if np.ma.is_masked(array_1) or np.ma.is_masked(array_2): mask_1 = np.ma.getmaskarray(array_1) mask_2 = np.ma.getmaskarray(array_2) np.testing.assert_equal(mask_1, mask_2) - np.testing.assert_allclose(array_1[~mask_1], array_2[~mask_2]) + np.testing.assert_allclose(array_1[~mask_1], array_2[~mask_2], rtol) else: - np.testing.assert_allclose(array_1, array_2) + np.testing.assert_allclose(array_1, array_2, rtol) def products_set_to_dict(products): @@ -445,7 +445,10 @@ def test_distance_metric( out_cube = product_ref.cubes[0] assert out_cube.shape == () assert out_cube.dtype == np.float32 - assert_allclose(out_cube.data, ref_data) + # an rtol=1e-6 is needed for numpy >=2.0 + assert_allclose(out_cube.data, + np.array(ref_data, dtype=np.float32), + rtol=1e-6) assert out_cube.var_name == var_name assert out_cube.long_name == long_name assert out_cube.standard_name is None @@ -620,7 +623,8 @@ def test_distance_metric_masked_data( expected_data = np.ma.masked_invalid(data) else: expected_data = np.array(data, dtype=np.float32) - assert_allclose(out_cube.data, expected_data) + # an rtol=1e-6 is needed for numpy >=2.0 + assert_allclose(out_cube.data, expected_data, rtol=1e-6) assert out_cube.var_name == var_name assert out_cube.long_name == long_name assert out_cube.standard_name is None From a4707ef6055d2bc02abc1624d2d6e835ed6fd306 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 16:33:00 +0100 Subject: [PATCH 31/62] add note on sqrt bug --- esmvalcore/preprocessor/_compare_with_refs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_compare_with_refs.py b/esmvalcore/preprocessor/_compare_with_refs.py index dfe2bbf88e..ae9032e06e 100644 --- a/esmvalcore/preprocessor/_compare_with_refs.py +++ b/esmvalcore/preprocessor/_compare_with_refs.py @@ -453,8 +453,10 @@ def _calculate_rmse( npx = get_array_module(squared_error) # need masked sqrt for numpy >=2.0 - # and dask.array.reductions.safe_sqrt for Dask + # and consequently dask.array.reductions.safe_sqrt for Dask # otherwise results will be computed ignoring masks + # see https://github.com/numpy/numpy/issues/25635 + # and https://docs.dask.org/en/stable/_modules/dask/array/reductions.html if npx.__name__ == "dask.array": da_squared_error = npx.ma.average(squared_error, axis=axis, From 266781ac24b00a41144439c51dde81d15078e5aa Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 16:33:56 +0100 Subject: [PATCH 32/62] temprary pin numpy<2 --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index bd3147381a..17b1bc576a 100644 --- a/environment.yml +++ b/environment.yml @@ -28,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy !=1.24.3 + - numpy !=1.24.3,<2.0.0 - packaging - pandas # !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From 73d455ba1ae3687afc08f0d00c347e6b1e597017 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 16:34:01 +0100 Subject: [PATCH 33/62] temprary pin numpy<2 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7c0ce1e45d..c3f408859d 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ 'nc-time-axis', # needed by iris.plot 'nested-lookup', 'netCDF4', - 'numpy!=1.24.3', + 'numpy!=1.24.3,<2.0.0', 'packaging', 'pandas', # !=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc 'pillow', From 3007575c36dba5b609eae8c7d1fe1ad226e93947 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 16:43:21 +0100 Subject: [PATCH 34/62] unpin and let numpy be two --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 17b1bc576a..bd3147381a 100644 --- a/environment.yml +++ b/environment.yml @@ -28,7 +28,7 @@ dependencies: - nc-time-axis - nested-lookup - netcdf4 - - numpy !=1.24.3,<2.0.0 + - numpy !=1.24.3 - packaging - pandas # !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 - pillow From 7386b7ec7af060ecf7dd9e253a6a39dc65bc1c71 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 21 Jun 2024 16:43:27 +0100 Subject: [PATCH 35/62] unpin and let numpy be two --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c3f408859d..7c0ce1e45d 100755 --- a/setup.py +++ b/setup.py @@ -46,7 +46,7 @@ 'nc-time-axis', # needed by iris.plot 'nested-lookup', 'netCDF4', - 'numpy!=1.24.3,<2.0.0', + 'numpy!=1.24.3', 'packaging', 'pandas', # !=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc 'pillow', From 043407a5fb77d02c44c57b64020265b5a55c88de Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 24 Jun 2024 13:32:32 +0100 Subject: [PATCH 36/62] use the force and xfail the icon test instead --- tests/integration/cmor/_fixes/icon/test_icon.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/integration/cmor/_fixes/icon/test_icon.py b/tests/integration/cmor/_fixes/icon/test_icon.py index b1607d07bf..afe315e332 100644 --- a/tests/integration/cmor/_fixes/icon/test_icon.py +++ b/tests/integration/cmor/_fixes/icon/test_icon.py @@ -1607,6 +1607,9 @@ def test_invalid_time_units(cubes_2d): # Test fix with (sub-)hourly data +# remove xfail when https://github.com/pandas-dev/pandas/issues/57002 +# gets fixed; pinning pandas not a viable solution due deps issues +@pytest.mark.xfail(reason='Bug in pandas needs be fixed.') def test_hourly_data(cubes_2d): """Test fix.""" fix = get_allvars_fix('Amon', 'tas') From a3ccff6b2830c3056b5026b6aef4589b00a7e7db Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 24 Jun 2024 14:02:47 +0100 Subject: [PATCH 37/62] remove commented out pandas pins --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index bd3147381a..6707a63498 100644 --- a/environment.yml +++ b/environment.yml @@ -30,7 +30,7 @@ dependencies: - netcdf4 - numpy !=1.24.3 - packaging - - pandas # !=2.2.0,!=2.2.1,!=2.2.2 # github.com/ESMValGroup/ESMValCore/pull/2305 and #2349 + - pandas - pillow - pip !=21.3 - prov From aefb52cf962ec2088c0b3b943c272207b83afb77 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 24 Jun 2024 14:02:58 +0100 Subject: [PATCH 38/62] remove commented out pandas pins --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 7c0ce1e45d..71061b7be0 100755 --- a/setup.py +++ b/setup.py @@ -48,7 +48,7 @@ 'netCDF4', 'numpy!=1.24.3', 'packaging', - 'pandas', # !=2.2.0,!=2.2.1,!=2.2.2', # GH #2305 #2349 etc + 'pandas', 'pillow', 'prov', 'psutil', From 17417276d6d0b200f06ea93546d45dd214f2cdc5 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 24 Jun 2024 14:08:50 +0100 Subject: [PATCH 39/62] unrun GA --- .github/workflows/run-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 2e1b0d3c42..9cf1d6308b 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -21,7 +21,6 @@ on: push: branches: - main - - numpy2-dev # run the test only if the PR is to main # turn it on if required #pull_request: From 4afc351a22b29db095d14a6b897f5b2e3c9e9241 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 3 Jul 2024 14:12:47 +0100 Subject: [PATCH 40/62] Update esmvalcore/preprocessor/_compare_with_refs.py Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com> --- esmvalcore/preprocessor/_compare_with_refs.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/esmvalcore/preprocessor/_compare_with_refs.py b/esmvalcore/preprocessor/_compare_with_refs.py index ae9032e06e..e2e1e602ff 100644 --- a/esmvalcore/preprocessor/_compare_with_refs.py +++ b/esmvalcore/preprocessor/_compare_with_refs.py @@ -451,21 +451,11 @@ def _calculate_rmse( weights = get_weights(cube, coords) if weighted else None squared_error = (cube.core_data() - reference.core_data())**2 npx = get_array_module(squared_error) - - # need masked sqrt for numpy >=2.0 - # and consequently dask.array.reductions.safe_sqrt for Dask - # otherwise results will be computed ignoring masks - # see https://github.com/numpy/numpy/issues/25635 - # and https://docs.dask.org/en/stable/_modules/dask/array/reductions.html - if npx.__name__ == "dask.array": - da_squared_error = npx.ma.average(squared_error, - axis=axis, - weights=weights) - rmse = npx.reductions.safe_sqrt(da_squared_error) + mse = npx.ma.average(squared_error, axis=axis, weights=weights) + if isinstance(mse, da.Array): + rmse = da.reductions.safe_sqrt(mse) else: - rmse = npx.ma.sqrt( - npx.ma.average(squared_error, axis=axis, weights=weights) - ) + rmse = np.ma.sqrt(mse) # Metadata metadata = CubeMetadata( From 85b2aa4f6523a4ec1d2eb2e2d00db12d17f6b405 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 3 Jul 2024 14:39:04 +0100 Subject: [PATCH 41/62] remove numpy2 related comment --- esmvalcore/preprocessor/_derive/co2s.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esmvalcore/preprocessor/_derive/co2s.py b/esmvalcore/preprocessor/_derive/co2s.py index 91023ad2cd..432e9f582a 100644 --- a/esmvalcore/preprocessor/_derive/co2s.py +++ b/esmvalcore/preprocessor/_derive/co2s.py @@ -15,7 +15,7 @@ def _get_first_unmasked_data(array, axis): indices = da.meshgrid( *[da.arange(array.shape[i]) for i in range(array.ndim) if i != axis], indexing='ij') - # numpy>=2.0 indices becomes a tuple + indices = list(indices) indices.insert(axis, indices_first_positive) first_unmasked_data = np.array(array)[tuple(indices)] From 05dea6644aee29f5da34d64215c71cbb3e6920a9 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Wed, 3 Jul 2024 14:40:46 +0100 Subject: [PATCH 42/62] remove numpy2 related comment --- esmvalcore/preprocessor/_time.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/esmvalcore/preprocessor/_time.py b/esmvalcore/preprocessor/_time.py index d0431cf8d2..65f067295a 100644 --- a/esmvalcore/preprocessor/_time.py +++ b/esmvalcore/preprocessor/_time.py @@ -1559,8 +1559,6 @@ def _transform_to_lst_eager( """ # Apart from the time index, all other dimensions will stay the same; this # is ensured with np.ogrid - # NOTE: in numpy 2.0 np.ogrid returns ndarray or tuple of ndarrays - # so item assignment can only be done after converting to a list idx = list(np.ogrid[tuple(slice(0, d) for d in data.shape)]) time_index = broadcast_to_shape( time_index, data.shape, (time_dim, lon_dim) From e6073eb65044c5f85cd568b5a36a765fe80390ea Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 27 Sep 2024 13:03:49 +0100 Subject: [PATCH 43/62] run precommit twice --- esmvalcore/preprocessor/_derive/co2s.py | 3 ++- esmvalcore/preprocessor/_regrid_esmpy.py | 2 +- esmvalcore/preprocessor/_regrid_unstructured.py | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/esmvalcore/preprocessor/_derive/co2s.py b/esmvalcore/preprocessor/_derive/co2s.py index e507d27c8f..649e552040 100644 --- a/esmvalcore/preprocessor/_derive/co2s.py +++ b/esmvalcore/preprocessor/_derive/co2s.py @@ -15,7 +15,8 @@ def _get_first_unmasked_data(array, axis): indices_first_positive = da.argmax(numerical_mask, axis=axis) indices = da.meshgrid( *[da.arange(array.shape[i]) for i in range(array.ndim) if i != axis], - indexing='ij') + indexing="ij", + ) indices = list(indices) indices.insert(axis, indices_first_positive) diff --git a/esmvalcore/preprocessor/_regrid_esmpy.py b/esmvalcore/preprocessor/_regrid_esmpy.py index 90aae36344..eab8e493dd 100755 --- a/esmvalcore/preprocessor/_regrid_esmpy.py +++ b/esmvalcore/preprocessor/_regrid_esmpy.py @@ -289,7 +289,7 @@ def get_grid( grid = esmpy.Grid( np.vstack(esmpy_lat.shape), num_peri_dims=num_peri_dims, - staggerloc=[esmpy.StaggerLoc.CENTER] + staggerloc=[esmpy.StaggerLoc.CENTER], ) grid.get_coords(ESMF_LON)[...] = esmpy_lon grid.get_coords(ESMF_LAT)[...] = esmpy_lat diff --git a/esmvalcore/preprocessor/_regrid_unstructured.py b/esmvalcore/preprocessor/_regrid_unstructured.py index 1376b9d51d..8bbae936ff 100644 --- a/esmvalcore/preprocessor/_regrid_unstructured.py +++ b/esmvalcore/preprocessor/_regrid_unstructured.py @@ -174,7 +174,7 @@ def _get_weights_and_idx( # explicitly casting to int32 since without it, in Numpy 2.0 # one gets OverflowError: Python integer 360 out of bounds for int8 # see notes https://numpy.org/devdocs/numpy_2_0_migration_guide.html - src_points_with_convex_hull[-2 * n_hull:-n_hull, 1] -= np.int32(360) + src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= np.int32(360) src_points_with_convex_hull[-n_hull:, 1] += np.int32(360) # Actual weights calculation From 803017d3e73b7d704f2a5af05cb8727f5114e874 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Fri, 27 Sep 2024 13:04:13 +0100 Subject: [PATCH 44/62] run precommit twice --- tests/integration/cmor/_fixes/icon/test_icon.py | 2 +- .../_compare_with_refs/test_compare_with_refs.py | 6 +++--- tests/unit/preprocessor/_time/test_time.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integration/cmor/_fixes/icon/test_icon.py b/tests/integration/cmor/_fixes/icon/test_icon.py index 0f0fb9a4a4..3d212f5a10 100644 --- a/tests/integration/cmor/_fixes/icon/test_icon.py +++ b/tests/integration/cmor/_fixes/icon/test_icon.py @@ -1712,7 +1712,7 @@ def test_invalid_time_units(cubes_2d): # remove xfail when https://github.com/pandas-dev/pandas/issues/57002 # gets fixed; pinning pandas not a viable solution due deps issues -@pytest.mark.xfail(reason='Bug in pandas needs be fixed.') +@pytest.mark.xfail(reason="Bug in pandas needs be fixed.") def test_hourly_data(cubes_2d): """Test fix.""" fix = get_allvars_fix("Amon", "tas") diff --git a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py index 284b6b6fe4..8767b8c33d 100644 --- a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py +++ b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py @@ -474,9 +474,9 @@ def test_distance_metric( assert out_cube.dtype == np.float32 assert not out_cube.has_lazy_data() # an rtol=1e-6 is needed for numpy >=2.0 - assert_allclose(out_cube.data, - np.array(ref_data, dtype=np.float32), - rtol=1e-6) + assert_allclose( + out_cube.data, np.array(ref_data, dtype=np.float32), rtol=1e-6 + ) assert out_cube.var_name == var_name assert out_cube.long_name == long_name assert out_cube.standard_name is None diff --git a/tests/unit/preprocessor/_time/test_time.py b/tests/unit/preprocessor/_time/test_time.py index 6954670e4b..f7fa3580f0 100644 --- a/tests/unit/preprocessor/_time/test_time.py +++ b/tests/unit/preprocessor/_time/test_time.py @@ -1014,7 +1014,7 @@ def test_season_not_available(self): ) # numpy>=2.0 these need to be explicitly cast to numpy strings - two_seasons = [np.str_('JASOND'), np.str_('JFMAMJ')] + two_seasons = [np.str_("JASOND"), np.str_("JFMAMJ")] msg = ( "Seasons ('DJF', 'MAM', 'JJA', 'SON') do not match prior season " f"extraction {two_seasons}." From c4cb2f15a1672a5ad1f26158157c02b24dae6e73 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 24 Oct 2024 14:00:51 +0100 Subject: [PATCH 45/62] unpin numpy --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 797e9bc81b..ea3fa1046d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,7 +50,7 @@ dependencies = [ "nc-time-axis", # needed by iris.plot "nested-lookup", "netCDF4", - "numpy!=1.24.3,<2.0.0", # avoid pulling 2.0.0rc1 + "numpy!=1.24.3", "packaging", "pandas", "pillow", From 9c5eace87c8c096f961216a84ce3c259db294f98 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Thu, 24 Oct 2024 14:12:00 +0100 Subject: [PATCH 46/62] well I have just found one of those rare occasions when merge resulted in a diff --- tests/integration/cmor/_fixes/icon/test_icon.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/integration/cmor/_fixes/icon/test_icon.py b/tests/integration/cmor/_fixes/icon/test_icon.py index 5ec7ca1a93..cfd3ea6726 100644 --- a/tests/integration/cmor/_fixes/icon/test_icon.py +++ b/tests/integration/cmor/_fixes/icon/test_icon.py @@ -1710,9 +1710,6 @@ def test_invalid_time_units(cubes_2d): # Test fix with (sub-)hourly data -# remove xfail when https://github.com/pandas-dev/pandas/issues/57002 -# gets fixed; pinning pandas not a viable solution due deps issues -@pytest.mark.xfail(reason="Bug in pandas needs be fixed.") def test_hourly_data(cubes_2d): """Test fix.""" fix = get_allvars_fix("Amon", "tas") From dddc0831b98305f7b55a7b0eee4ec18480ed3792 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 14:47:17 +0000 Subject: [PATCH 47/62] pin iris --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index bc58718947..d57837fca0 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - fire - geopy - humanfriendly - - iris >=3.10.0 + - iris >=3.11.0 # earliest numpy2-supporting - iris-esmf-regrid >=0.11.0 - iris-grib >=0.20.0 # github.com/ESMValGroup/ESMValCore/issues/2535 - isodate >=0.7.0 # incompatible with very old 0.6.1 From 858ae1179c7f69f8cbe8f8b7d75c32c5bed9dbb9 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 14:47:25 +0000 Subject: [PATCH 48/62] pin iris --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ea3fa1046d..ca2150e116 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ dependencies = [ "pyyaml", "requests", "scipy>=1.6", - "scitools-iris>=3.10.0", + "scitools-iris>=3.11.0", # earliest numpy2-supporting "shapely>=2.0.0", "stratify>=0.3", "yamale", From e636c7b4ddee89ca79554adf0693cc8c6caa3c37 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 14:47:40 +0000 Subject: [PATCH 49/62] rerun GA tests see all is fine --- .github/workflows/run-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 743ac00f45..a721de3f4e 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -21,6 +21,7 @@ on: push: branches: - main + - numpy2-dev # run the test only if the PR is to main # turn it on if required #pull_request: From acf78389f670948e75fb46926f55591d08587091 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:16:43 +0000 Subject: [PATCH 50/62] unrun GA --- .github/workflows/run-tests.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index a721de3f4e..743ac00f45 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -21,7 +21,6 @@ on: push: branches: - main - - numpy2-dev # run the test only if the PR is to main # turn it on if required #pull_request: From 801b7d059e6f5432e41b52431190933cc26fae01 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:29:12 +0000 Subject: [PATCH 51/62] change inline comment --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index d57837fca0..63f6126070 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - fire - geopy - humanfriendly - - iris >=3.11.0 # earliest numpy2-supporting + - iris >=3.11.0 # 3.11 first to support numpy2 and Python3.13 - iris-esmf-regrid >=0.11.0 - iris-grib >=0.20.0 # github.com/ESMValGroup/ESMValCore/issues/2535 - isodate >=0.7.0 # incompatible with very old 0.6.1 From bab038dbf4bddad47c8f776c0e42ad0b90af2228 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:29:20 +0000 Subject: [PATCH 52/62] change inline comment --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ca2150e116..b360692140 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ dependencies = [ "pyyaml", "requests", "scipy>=1.6", - "scitools-iris>=3.11.0", # earliest numpy2-supporting + "scitools-iris>=3.11.0", # 3.11 first to support numpy2 and Python3.13 "shapely>=2.0.0", "stratify>=0.3", "yamale", From d59d60611cfff9f423c949fc3c872cc672752211 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:33:08 +0000 Subject: [PATCH 53/62] cleanup --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index 63f6126070..a541b886ab 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - fire - geopy - humanfriendly - - iris >=3.11.0 # 3.11 first to support numpy2 and Python3.13 + - iris >=3.11 # 3.11 first to support numpy2 and Python3.13 - iris-esmf-regrid >=0.11.0 - iris-grib >=0.20.0 # github.com/ESMValGroup/ESMValCore/issues/2535 - isodate >=0.7.0 # incompatible with very old 0.6.1 From b81db5ffba42a492d9f8e080d16259e17ca26975 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:33:20 +0000 Subject: [PATCH 54/62] cleanup --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b360692140..b42d0b7d8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ dependencies = [ "pyyaml", "requests", "scipy>=1.6", - "scitools-iris>=3.11.0", # 3.11 first to support numpy2 and Python3.13 + "scitools-iris>=3.11", # 3.11 first to support numpy2 and Python3.13 "shapely>=2.0.0", "stratify>=0.3", "yamale", From 3bd04689fddc74aba76696ef02e0732b1f312ea3 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:47:27 +0000 Subject: [PATCH 55/62] Update esmvalcore/preprocessor/_regrid_esmpy.py Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com> --- esmvalcore/preprocessor/_regrid_esmpy.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/esmvalcore/preprocessor/_regrid_esmpy.py b/esmvalcore/preprocessor/_regrid_esmpy.py index 5fcf7ed809..b5da1e368c 100755 --- a/esmvalcore/preprocessor/_regrid_esmpy.py +++ b/esmvalcore/preprocessor/_regrid_esmpy.py @@ -284,8 +284,6 @@ def get_grid( else: num_peri_dims = 0 - # previous to numpy 2.0, a np.array(esmpy_lat.shape) was used - # numpy>=2.0 throws ValueError: matrix transpose with ndim<2 is undefined grid = esmpy.Grid( np.vstack(esmpy_lat.shape), num_peri_dims=num_peri_dims, From 19d770088408dfca3dd06fa94f76c1947c24c297 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:48:00 +0000 Subject: [PATCH 56/62] Update pyproject.toml Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com> --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index b42d0b7d8f..efbb3590c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,7 +61,7 @@ dependencies = [ "pyyaml", "requests", "scipy>=1.6", - "scitools-iris>=3.11", # 3.11 first to support numpy2 and Python3.13 + "scitools-iris>=3.11", # 3.11 first to support Numpy 2 and Python 3.13 "shapely>=2.0.0", "stratify>=0.3", "yamale", From 8adcd1b2bc12da871256b3be302a770cd8bc8580 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:48:13 +0000 Subject: [PATCH 57/62] Update environment.yml Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com> --- environment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/environment.yml b/environment.yml index a541b886ab..7a4b6e2201 100644 --- a/environment.yml +++ b/environment.yml @@ -18,7 +18,7 @@ dependencies: - fire - geopy - humanfriendly - - iris >=3.11 # 3.11 first to support numpy2 and Python3.13 + - iris >=3.11 # 3.11 first to support Numpy 2 and Python 3.13 - iris-esmf-regrid >=0.11.0 - iris-grib >=0.20.0 # github.com/ESMValGroup/ESMValCore/issues/2535 - isodate >=0.7.0 # incompatible with very old 0.6.1 From f11ad18e9edf184b751882c79d7925ae93b0f9f3 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:48:30 +0000 Subject: [PATCH 58/62] Update tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py Co-authored-by: Manuel Schlund <32543114+schlunma@users.noreply.github.com> --- .../preprocessor/_compare_with_refs/test_compare_with_refs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py index 9289fd0519..1140323e61 100644 --- a/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py +++ b/tests/unit/preprocessor/_compare_with_refs/test_compare_with_refs.py @@ -744,7 +744,6 @@ def test_distance_metric_fully_masked_data( assert out_cube.dtype == np.float64 expected_data = np.ma.masked_all(()) - print("out/in/metric", out_cube.data, expected_data, metric) assert_allclose(out_cube.data, expected_data) assert out_cube.var_name == var_name assert out_cube.long_name == long_name From e81c0267e1568e384b51bb8c4fad31454b92b2b6 Mon Sep 17 00:00:00 2001 From: Valeriu Predoi Date: Mon, 11 Nov 2024 15:53:14 +0000 Subject: [PATCH 59/62] revert to old syntax to recheck --- esmvalcore/preprocessor/_regrid_unstructured.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/esmvalcore/preprocessor/_regrid_unstructured.py b/esmvalcore/preprocessor/_regrid_unstructured.py index 8bbae936ff..3c289b1e13 100644 --- a/esmvalcore/preprocessor/_regrid_unstructured.py +++ b/esmvalcore/preprocessor/_regrid_unstructured.py @@ -174,8 +174,8 @@ def _get_weights_and_idx( # explicitly casting to int32 since without it, in Numpy 2.0 # one gets OverflowError: Python integer 360 out of bounds for int8 # see notes https://numpy.org/devdocs/numpy_2_0_migration_guide.html - src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= np.int32(360) - src_points_with_convex_hull[-n_hull:, 1] += np.int32(360) + src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= 360 + src_points_with_convex_hull[-n_hull:, 1] += 360 # Actual weights calculation (weights, indices) = self._calculate_weights( From c99f262a1dd13b44dfb25b09f9b9371bda7360ec Mon Sep 17 00:00:00 2001 From: Manuel Schlund Date: Mon, 11 Nov 2024 17:33:40 +0100 Subject: [PATCH 60/62] Don't use int8 --- esmvalcore/preprocessor/_regrid.py | 2 +- esmvalcore/preprocessor/_regrid_unstructured.py | 8 ++------ tests/unit/preprocessor/_regrid/__init__.py | 4 ++-- tests/unit/preprocessor/_regrid/test__create_cube.py | 2 +- tests/unit/preprocessor/_regrid/test_extract_levels.py | 2 +- 5 files changed, 7 insertions(+), 11 deletions(-) diff --git a/esmvalcore/preprocessor/_regrid.py b/esmvalcore/preprocessor/_regrid.py index 2fc34e4d85..10511102e2 100644 --- a/esmvalcore/preprocessor/_regrid.py +++ b/esmvalcore/preprocessor/_regrid.py @@ -209,7 +209,7 @@ def _generate_cube_from_dimcoords(latdata, londata, circular: bool = False): # Construct the resultant stock cube, with dummy data. shape = (latdata.size, londata.size) - dummy = np.empty(shape, dtype=np.dtype("int8")) + dummy = np.empty(shape, dtype=np.int32) coords_spec = [(lats, 0), (lons, 1)] cube = Cube(dummy, dim_coords_and_dims=coords_spec) diff --git a/esmvalcore/preprocessor/_regrid_unstructured.py b/esmvalcore/preprocessor/_regrid_unstructured.py index 3c289b1e13..4a7e8a3113 100644 --- a/esmvalcore/preprocessor/_regrid_unstructured.py +++ b/esmvalcore/preprocessor/_regrid_unstructured.py @@ -170,12 +170,8 @@ def _get_weights_and_idx( src_points_with_convex_hull = self._add_convex_hull_twice( src_points, hull.vertices ) - - # explicitly casting to int32 since without it, in Numpy 2.0 - # one gets OverflowError: Python integer 360 out of bounds for int8 - # see notes https://numpy.org/devdocs/numpy_2_0_migration_guide.html - src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= 360 - src_points_with_convex_hull[-n_hull:, 1] += 360 + src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= 360.0 + src_points_with_convex_hull[-n_hull:, 1] += 360.0 # Actual weights calculation (weights, indices) = self._calculate_weights( diff --git a/tests/unit/preprocessor/_regrid/__init__.py b/tests/unit/preprocessor/_regrid/__init__.py index c2b79e2c0b..55b99b5b58 100644 --- a/tests/unit/preprocessor/_regrid/__init__.py +++ b/tests/unit/preprocessor/_regrid/__init__.py @@ -11,7 +11,7 @@ def _make_vcoord(data, dtype=None): """Create a synthetic test vertical coordinate.""" if dtype is None: - dtype = np.dtype("int8") + dtype = np.int32 if isinstance(data, int): data = np.arange(data, dtype=dtype) @@ -45,7 +45,7 @@ def _make_cube( ): """Create a 3d synthetic test cube.""" if dtype is None: - dtype = np.dtype("int8") + dtype = np.int32 if not isinstance(data, np.ndarray): data = np.empty(data, dtype=dtype) diff --git a/tests/unit/preprocessor/_regrid/test__create_cube.py b/tests/unit/preprocessor/_regrid/test__create_cube.py index 4ec1e97b60..a7ad01782a 100644 --- a/tests/unit/preprocessor/_regrid/test__create_cube.py +++ b/tests/unit/preprocessor/_regrid/test__create_cube.py @@ -12,7 +12,7 @@ class Test(tests.Test): def setUp(self): shape = (3, 2, 1) - self.dtype = np.dtype("int8") + self.dtype = np.int32 self.cube = _make_cube(shape, dtype=self.dtype) def test_invalid_shape__data_mismatch_with_levels(self): diff --git a/tests/unit/preprocessor/_regrid/test_extract_levels.py b/tests/unit/preprocessor/_regrid/test_extract_levels.py index 1103afab87..e1b14b7a14 100644 --- a/tests/unit/preprocessor/_regrid/test_extract_levels.py +++ b/tests/unit/preprocessor/_regrid/test_extract_levels.py @@ -24,7 +24,7 @@ class Test(tests.Test): def setUp(self): self.shape = (3, 2, 1) self.z = self.shape[0] - self.dtype = np.dtype("int8") + self.dtype = np.int32 data = np.arange(np.prod(self.shape), dtype=self.dtype).reshape( self.shape ) From 280e692828fe2170eb838b5b58bf45d4a5949343 Mon Sep 17 00:00:00 2001 From: Manuel Schlund Date: Mon, 11 Nov 2024 17:35:39 +0100 Subject: [PATCH 61/62] Restore nice error string when invalid season(s) are given --- esmvalcore/preprocessor/_time.py | 4 +++- tests/unit/preprocessor/_time/test_time.py | 5 +---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/esmvalcore/preprocessor/_time.py b/esmvalcore/preprocessor/_time.py index 627dd3e2fd..b3e4ab5b0f 100644 --- a/esmvalcore/preprocessor/_time.py +++ b/esmvalcore/preprocessor/_time.py @@ -632,7 +632,9 @@ def seasonal_statistics( cube, "time", name="clim_season", seasons=seasons ) else: - old_seasons = sorted(set(cube.coord("clim_season").points)) + old_seasons = sorted( + {str(s) for s in cube.coord("clim_season").points} + ) if not all(osea in seasons for osea in old_seasons): raise ValueError( f"Seasons {seasons} do not match prior season extraction " diff --git a/tests/unit/preprocessor/_time/test_time.py b/tests/unit/preprocessor/_time/test_time.py index c7f8db016a..6a9d78747d 100644 --- a/tests/unit/preprocessor/_time/test_time.py +++ b/tests/unit/preprocessor/_time/test_time.py @@ -1063,12 +1063,9 @@ def test_season_not_available(self): name="clim_season", seasons=["JFMAMJ", "JASOND"], ) - - # numpy>=2.0 these need to be explicitly cast to numpy strings - two_seasons = [np.str_("JASOND"), np.str_("JFMAMJ")] msg = ( "Seasons ('DJF', 'MAM', 'JJA', 'SON') do not match prior season " - f"extraction {two_seasons}." + "extraction ['JASOND', 'JFMAMJ']." ) with pytest.raises(ValueError, match=re.escape(msg)): seasonal_statistics(cube, "mean") From 24f25495e8ecab61bca2fc9bec20dfed9d96eacc Mon Sep 17 00:00:00 2001 From: Manuel Schlund Date: Mon, 11 Nov 2024 17:48:17 +0100 Subject: [PATCH 62/62] Cast 360 to original dtype --- esmvalcore/preprocessor/_regrid_unstructured.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/esmvalcore/preprocessor/_regrid_unstructured.py b/esmvalcore/preprocessor/_regrid_unstructured.py index 4a7e8a3113..b2f09f2d3b 100644 --- a/esmvalcore/preprocessor/_regrid_unstructured.py +++ b/esmvalcore/preprocessor/_regrid_unstructured.py @@ -170,8 +170,9 @@ def _get_weights_and_idx( src_points_with_convex_hull = self._add_convex_hull_twice( src_points, hull.vertices ) - src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= 360.0 - src_points_with_convex_hull[-n_hull:, 1] += 360.0 + lon_period = np.array(360, dtype=src_points_with_convex_hull.dtype) + src_points_with_convex_hull[-2 * n_hull : -n_hull, 1] -= lon_period + src_points_with_convex_hull[-n_hull:, 1] += lon_period # Actual weights calculation (weights, indices) = self._calculate_weights(