Skip to content

Commit

Permalink
Fix "if index"-like test with None test
Browse files Browse the repository at this point in the history
Two checks related to multidimensional indices were incorrectly apply
generic `if index` tests, which return false if `index` is zero.

This raised errors in two cases:

1. The end-bound of an array a(0), which is bounded by 1, was
   incorrectly set to None rather than 1, and treated as a floating
   index.

2. The `FIndex` iterator would incorrectly terminate higher ranks if the
   current higher rank index was zero.

These errors occur because we use `None` when the index bounds are
unspecified, and are implicitly determined when values are provided.

Both of these tests have been replaced with `if None` tests, which
appear to have resolved these errors.
  • Loading branch information
marshallward committed Jun 6, 2023
1 parent 4fd9d66 commit 52d4c29
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion f90nml/findex.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def __next__(self):
state = self.current[:]
# Allow the final index to exceed self.end[-1] as a finalisation check
for rank, idx in enumerate(self.current):
if ((not self.end[rank] or idx < (self.end[rank] - 1)) or
if ((self.end[rank] is None or idx < (self.end[rank] - 1)) or
rank == (len(self.current) - 1)):
self.current[rank] = idx + self.step[rank]
break
Expand Down
3 changes: 1 addition & 2 deletions f90nml/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,6 @@ def _parse_variable(self, parent, patch_nml=None):

if not v_idx:
v_values = delist(v_values)

return v_name, v_values

def _parse_indices(self):
Expand Down Expand Up @@ -711,7 +710,7 @@ def _parse_index(self, v_name):
raise
elif self.token in (',', ')'):
# Replace index with single-index range
if i_start:
if i_start is not None:
i_end = 1 + i_start

# Stride index
Expand Down

0 comments on commit 52d4c29

Please sign in to comment.