Skip to content

Commit 99ff096

Browse files
Fixing basegrid unit tests
1 parent 069ae59 commit 99ff096

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

parcels/basegrid.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def search(self, z: float, y: float, x: float, ei=None) -> dict[str, tuple[int,
6969
"""
7070
...
7171

72-
def ravel_index(self, axis_indices: dict[str, int]) -> int:
72+
def ravel_index(self, axis_indices: dict[str, np.ndarray]) -> np.ndarray:
7373
"""
7474
Convert a dictionary of axis indices to a single encoded index (ei).
7575
@@ -79,7 +79,7 @@ def ravel_index(self, axis_indices: dict[str, int]) -> int:
7979
8080
Parameters
8181
----------
82-
axis_indices : dict[str, int]
82+
axis_indices : dict[str, np.ndarray(int)]
8383
A dictionary mapping axis names to their corresponding indices.
8484
The expected keys depend on the grid dimensionality and type:
8585
@@ -90,8 +90,8 @@ def ravel_index(self, axis_indices: dict[str, int]) -> int:
9090
9191
Returns
9292
-------
93-
int
94-
The encoded index (ei) representing the unique grid cell or face.
93+
np.ndarray(int)
94+
The encoded indices (ei) representing the unique grid cells or faces.
9595
9696
Raises
9797
------

tests/v4/test_basegrid.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ def get_axis_dim(self, axis: str) -> int:
2626
@pytest.mark.parametrize(
2727
"grid",
2828
[
29-
TestGrid({"Z": 10, "Y": 20, "X": 30}),
30-
TestGrid({"Z": 5, "Y": 15}),
31-
TestGrid({"Z": 8}),
32-
TestGrid({"Z": 12, "FACE": 25}),
29+
TestGrid({"Z": [10], "Y": [20], "X": [30]}),
30+
TestGrid({"Z": [5], "Y": [15]}),
31+
TestGrid({"Z": [8]}),
32+
TestGrid({"Z": [12], "FACE": [25]}),
3333
],
3434
)
3535
def test_basegrid_ravel_unravel_index(grid):
3636
axes = grid.axes
3737
dimensionalities = (grid.get_axis_dim(axis) for axis in axes)
38-
all_possible_axis_indices = itertools.product(*[range(dim) for dim in dimensionalities])
38+
all_possible_axis_indices = itertools.product(*[range(dim[0]) for dim in dimensionalities])
3939

4040
encountered_eis = []
4141

4242
for axis_indices_numeric in all_possible_axis_indices:
43-
axis_indices = dict(zip(axes, axis_indices_numeric, strict=True))
43+
axis_indices = {axis: [index] for axis, index in zip(axes, axis_indices_numeric, strict=True)}
4444

4545
ei = grid.ravel_index(axis_indices)
4646
axis_indices_test = grid.unravel_index(ei)
4747
assert axis_indices_test == axis_indices
48-
encountered_eis.append(ei)
48+
encountered_eis.append(ei[0])
4949

5050
encountered_eis = sorted(encountered_eis)
5151
assert len(set(encountered_eis)) == len(encountered_eis), "Raveled indices are not unique."

0 commit comments

Comments
 (0)