Skip to content

Commit

Permalink
Fix zero-length slicing in SolutionArray
Browse files Browse the repository at this point in the history
Fixes #837
  • Loading branch information
sin-ha authored Jun 5, 2020
1 parent 113bd4b commit 437d870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ def __getitem__(self, index):
states = self._states[index]
if(isinstance(states, list)):
num_rows = len(states)
if num_rows == 0:
states = None
return SolutionArray(self._phase, num_rows, states)
else:
shape = states.shape[:-1]
Expand Down
11 changes: 11 additions & 0 deletions interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1789,3 +1789,14 @@ def test_slice_SolutionArray(self):
soln = ct.SolutionArray(self.gas, 10)
arr = soln[2:9:3]
self.assertEqual(len(arr.T), 3)

def test_zero_length_slice_SolutionArray(self):
states = ct.SolutionArray(self.gas, 4)
arr1 = states[3:3]
self.assertEqual(len(arr1.T), 0)
self.assertEqual(arr1.X.shape, (0,9))
self.assertEqual(arr1.n_reactions, 28)

states.TP = [100,300,900,323.23], ct.one_atm
arr2 = states[slice(0)]
self.assertEqual(len(arr2.T), 0)

0 comments on commit 437d870

Please sign in to comment.