From a19b4090fad6705d9d6ad89ce2c2987252e617cd Mon Sep 17 00:00:00 2001 From: Patrick Peglar Date: Fri, 20 Dec 2024 12:52:04 +0000 Subject: [PATCH] Simplify 'scramble' operation. --- .../tests/unit/util/test_equalise_cubes.py | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/lib/iris/tests/unit/util/test_equalise_cubes.py b/lib/iris/tests/unit/util/test_equalise_cubes.py index bb29b47314..5aa0e28c2e 100644 --- a/lib/iris/tests/unit/util/test_equalise_cubes.py +++ b/lib/iris/tests/unit/util/test_equalise_cubes.py @@ -8,7 +8,6 @@ from cf_units import Unit import numpy as np -from numpy.random import Generator import pytest from iris.coords import DimCoord @@ -17,29 +16,10 @@ from iris.warnings import IrisUserWarning -def _scramble(inputs, rng=95297): - # Reorder items (IN PLACE) to check that order does not affect operation - # NOTE: the "magic" number is chosen because it happens to encode a permutation - # which is usefully non-trivial for small numbers - # examples: - # [0, 1] --> [1, 0] - # [0, 1, 2] --> [1, 2, 0] - # [0, 1, 2, 3] --> [1, 2, 3, 0] - # [0, 1, 2, 3, 4] --> [1, 2, 3, 0, 4] - # [0, 1, 2, 3, 4, 5] --> [1, 3, 2, 0, 5, 4] - # [0, 1, 2, 3, 4, 5, 6] --> [1, 5, 3, 2, 0, 6, 4] - if not isinstance(rng, Generator): - rng = np.random.default_rng(rng) - n_inputs = len(inputs) - # NOTE: make object array of explicit shape + fill it, - # since np.array(inputs) *fails* specifically with a list of metadata objects - inputs_array = np.empty((n_inputs,), dtype=object) - inputs_array[:] = inputs - n_inputs = inputs_array.shape[0] - scramble_inds = rng.permutation(n_inputs) - inputs_array = inputs_array[scramble_inds] - # Modify input list **BUT N.B. IN PLACE** - inputs[:] = inputs_array +def _scramble(inputs): + # Reorder items (IN PLACE) to check that order does not affect operation. + # Rather than anything more clever, we'll settle for just reversing the order. + inputs[:] = inputs[::-1] @pytest.fixture(params=["off", "on", "applyall", "scrambled"])