Skip to content

Commit 2f8f685

Browse files
committed
[Thermo] Fix slicing of SolutionArray objects
Fixes issue #804
1 parent 7450e9a commit 2f8f685

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

interfaces/cython/cantera/composite.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,12 @@ def __init__(self, phase, shape=(0,), states=None, extra=None):
535535

536536
def __getitem__(self, index):
537537
states = self._states[index]
538-
shape = states.shape[:-1]
539-
return SolutionArray(self._phase, shape, states)
538+
if isinstance(states, list):
539+
rows = len(states)
540+
return SolutionArray(self._phase, rows, states)
541+
else:
542+
shape = states.shape[:-1]
543+
return SolutionArray(self._phase, shape, states)
540544

541545
def __getattr__(self, name):
542546
if name in self._extra:

interfaces/cython/cantera/test/test_thermo.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,11 @@ def test_append(self):
16651665
self.assertNear(states.P[-1], 1e4)
16661666
self.assertNear(states.T[-1], 300)
16671667

1668+
def test_slice(self):
1669+
states = ct.SolutionArray(self.gas, 10)
1670+
arr = states[::2]
1671+
self.assertEqual(len(arr.T), 5)
1672+
16681673
def test_purefluid(self):
16691674
water = ct.Water()
16701675
states = ct.SolutionArray(water, 5)

0 commit comments

Comments
 (0)