diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index dd204498ee..513cb663e9 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -210,6 +210,12 @@ def test_setCompositionSlice(self): self.assertNear(X[0], 0.1) self.assertNear(X[3], 0.9) + def test_setCompositionSingleSpecies(self): + gas = ct.Solution('argon.xml') + gas.X = [1] + gas.Y = np.array([[1.001]]) + self.assertEqual(gas.Y[0], 1.0) + def test_setCompositionSlice_bad(self): with self.assertRaises(ValueError): self.phase['H2','O2'].Y = [0.1, 0.2, 0.3] diff --git a/interfaces/cython/cantera/thermo.pyx b/interfaces/cython/cantera/thermo.pyx index b2673fb904..4bbe409452 100644 --- a/interfaces/cython/cantera/thermo.pyx +++ b/interfaces/cython/cantera/thermo.pyx @@ -492,6 +492,9 @@ cdef class ThermoPhase(_SolutionBase): cdef np.ndarray[np.double_t, ndim=1] data values = np.squeeze(values) + if values.ndim == 0: + values = values[np.newaxis] # corner case for single-species phases + if len(values) == self.n_species: data = np.ascontiguousarray(values, dtype=np.double) elif len(values) == len(self._selected_species):