Skip to content

Commit 83bbc0a

Browse files
committed
Implement fix for Numpy for backward compatibility in gcpy/regrid.py
gcpy/regrid.py - Added a try/except block to allow either np.prod or np.product to be used, depending on the Numpy version. np.product was renamed to np.prod in Numpy 2.0. CHANGELOG.md - Updated accordingly Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
1 parent 1aaf010 commit 83bbc0a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1111

1212
### Fixed
1313
- Allow using a template at different grid resolutions in `gcpy/regrid_restart_file.py`
14+
- Implemented a workaround in `gcpy/regrid.py` to allow use of either `np.product` or `np.prod` depending on the Numpy version
1415

1516
## [1.7.1] - 2026-02-03
1617
### Changed

gcpy/regrid.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,14 @@ def regrid_vertical(src_data_3d, xmat_regrid, target_levs=None):
10941094

10951095
nlev_out = xmat_renorm.shape[1]
10961096
out_shape = [nlev_out] + list(src_data_3d.shape[1:])
1097-
n_other = np.product(src_data_3d.shape[1:])
1097+
# ------------------------------------------------------------------
1098+
# The np.product function was changed to np.prod in version 2.0,
1099+
# so implement this workaround for backward compatibility.
1100+
try:
1101+
np_other = np.prod(src_data_3d.shape[1:]) # NumPy >= 2.0
1102+
except AttributeError:
1103+
np_other = np.product(src_data_3d.shape[1:]) # NumPy < 2.0
1104+
# ------------------------------------------------------------------
10981105
temp_data = np.zeros((nlev_out, n_other))
10991106
in_data = np.reshape(np.array(src_data_3d), (nlev_in, n_other))
11001107
for ix in range(n_other):

0 commit comments

Comments
 (0)