From b6e39d758fc17e167b9323b25484965453846dbf Mon Sep 17 00:00:00 2001 From: Alex Chamberlain-Clay <68277260+acchamber@users.noreply.github.com> Date: Thu, 21 Sep 2023 16:13:07 +0100 Subject: [PATCH] Updated all np.product calls to np.prod (#5493) * Updated all np.product calls to np.prod * added whats new * review responses * no typos here * added link to name * Update docs/src/whatsnew/latest.rst Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com> * Update docs/src/whatsnew/latest.rst Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com> --------- Co-authored-by: Elias <110238618+ESadek-MO@users.noreply.github.com> --- docs/src/whatsnew/latest.rst | 6 ++++++ lib/iris/fileformats/_structured_array_identification.py | 2 +- lib/iris/pandas.py | 2 +- lib/iris/tests/integration/netcdf/test_thread_safety.py | 2 +- lib/iris/tests/unit/pandas/test_pandas.py | 6 +++--- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/src/whatsnew/latest.rst b/docs/src/whatsnew/latest.rst index 35b6121c41..a9b470296f 100644 --- a/docs/src/whatsnew/latest.rst +++ b/docs/src/whatsnew/latest.rst @@ -82,6 +82,9 @@ This document explains the changes made to Iris for this release working properly. (Main pull request: :pull:`5437`, more detail: :pull:`5430`, :pull:`5431`, :pull:`5432`, :pull:`5434`, :pull:`5436`) +#. `@acchamber`_ removed several warnings from iris related to Numpy 1.25 deprecations. + (:pull:`5493`) + #. `@trexfeathers`_ replaced all uses of the ``logging.WARNING`` level, in favour of using Python warnings, following team agreement. (:pull:`5488`) @@ -90,11 +93,14 @@ This document explains the changes made to Iris for this release + .. comment Whatsnew author names (@github name) in alphabetical order. Note that, core dev names are automatically included by the common_links.inc: .. _@scottrobinson02: https://github.com/scottrobinson02 +.. _@acchamber: https://github.com/acchamber + .. comment Whatsnew resources in alphabetical order: diff --git a/lib/iris/fileformats/_structured_array_identification.py b/lib/iris/fileformats/_structured_array_identification.py index b313500de7..11c62983e3 100644 --- a/lib/iris/fileformats/_structured_array_identification.py +++ b/lib/iris/fileformats/_structured_array_identification.py @@ -417,7 +417,7 @@ def filter_strides_of_length(length): # If we are to build another dimension on top of this possible # structure, we need to compute the stride that would be # needed for that dimension. - next_stride = np.product( + next_stride = np.prod( [struct.size for (_, struct) in potential] ) diff --git a/lib/iris/pandas.py b/lib/iris/pandas.py index 4d6681e94e..4c06530627 100644 --- a/lib/iris/pandas.py +++ b/lib/iris/pandas.py @@ -398,7 +398,7 @@ def as_cubes( cube_shape = getattr(pandas_index, "levshape", (pandas_index.nunique(),)) n_rows = len(pandas_structure) - if np.product(cube_shape) > n_rows: + if np.prod(cube_shape) > n_rows: message = ( f"Not all index values have a corresponding row - {n_rows} rows " f"cannot be reshaped into {cube_shape}. Consider padding with NaN " diff --git a/lib/iris/tests/integration/netcdf/test_thread_safety.py b/lib/iris/tests/integration/netcdf/test_thread_safety.py index 5ed32d0671..c5779250a2 100644 --- a/lib/iris/tests/integration/netcdf/test_thread_safety.py +++ b/lib/iris/tests/integration/netcdf/test_thread_safety.py @@ -38,7 +38,7 @@ def tiny_chunks(): def _check_tiny_loaded_chunks(cube: Cube): assert cube.has_lazy_data() cube_lazy_data = cube.core_data() - assert np.product(cube_lazy_data.chunksize) < cube_lazy_data.size + assert np.prod(cube_lazy_data.chunksize) < cube_lazy_data.size with dask.config.set({"array.chunk-size": "1KiB"}): yield _check_tiny_loaded_chunks diff --git a/lib/iris/tests/unit/pandas/test_pandas.py b/lib/iris/tests/unit/pandas/test_pandas.py index fd716bd7c9..d74d7cad9c 100644 --- a/lib/iris/tests/unit/pandas/test_pandas.py +++ b/lib/iris/tests/unit/pandas/test_pandas.py @@ -1075,7 +1075,7 @@ def test_ancillary_variable(self): def test_3d_with_2d_coord(self): df = self._create_pandas(index_levels=3) coord_shape = df.index.levshape[:2] - coord_values = np.arange(np.product(coord_shape)) + coord_values = np.arange(np.prod(coord_shape)) coord_name = "foo" df[coord_name] = coord_values.repeat(df.index.levshape[-1]) result = iris.pandas.as_cubes(df, aux_coord_cols=[coord_name]) @@ -1089,7 +1089,7 @@ def test_3d_with_2d_coord(self): def test_coord_varies_all_indices(self): df = self._create_pandas(index_levels=3) coord_shape = df.index.levshape - coord_values = np.arange(np.product(coord_shape)) + coord_values = np.arange(np.prod(coord_shape)) coord_name = "foo" df[coord_name] = coord_values result = iris.pandas.as_cubes(df, aux_coord_cols=[coord_name]) @@ -1105,7 +1105,7 @@ def test_category_coord(self): # increment. df = self._create_pandas(index_levels=2) coord_shape = df.index.levshape - coord_values = np.arange(np.product(coord_shape)) + coord_values = np.arange(np.prod(coord_shape)) coord_name = "foo" # Create a repeating value along a dimension.