Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed slicing update #837

Merged
merged 2 commits into from
Jun 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,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 @@ -1803,3 +1803,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)