diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index 2c126e08a08..e9bec7f5270 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -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] diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 16ba5f6b507..5c5043f00ad 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -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) + + #tests for edge cases in sliced solutionArray + 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)