Skip to content

Commit 8bc9b11

Browse files
committed
Merge PR #416 (Implement fix in gcpy/regrid.py for numpy)
This merge brings PR #416 (Implement fix in gcpy/regrid.py for numpy backward compatibility, by @yantosca) into the GCPy development stream. PR #146 adds a try/except block (in routine regrid_vertical of gcpy/regrid.py) to first call np.prod, and then if that fails, to call np.product. The np.product routine was renamed to np.prod in Numpy 2.0. This will ensure backwards compatibility with older Numpy versions. Signed-off-by: Bob Yantosca <yantosca@seas.harvard.edu>
2 parents d42cda6 + 83bbc0a commit 8bc9b11

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
@@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
1212

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

1617
## [1.7.1] - 2026-02-03
1718
### 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)