From 18a1c1f6796050bb55c914c750a60ebd85cb70ea Mon Sep 17 00:00:00 2001 From: sin-ha Date: Tue, 14 Apr 2020 19:56:10 +0530 Subject: [PATCH] Removed empty initialisation of extra columns and formatting updates --- interfaces/cython/cantera/composite.py | 12 +----- interfaces/cython/cantera/test/test_thermo.py | 38 +++++++++---------- 2 files changed, 21 insertions(+), 29 deletions(-) diff --git a/interfaces/cython/cantera/composite.py b/interfaces/cython/cantera/composite.py index 3bd0fdb91f7..008f85ce4bc 100644 --- a/interfaces/cython/cantera/composite.py +++ b/interfaces/cython/cantera/composite.py @@ -517,10 +517,10 @@ def __init__(self, phase, shape=(0,), states=None, extra=None): self._extra = {} - if isinstance(extra,str): + if isinstance(extra, str): extra = [extra] - if isinstance(extra, (list,tuple,np.ndarray)) and all(isinstance(name, str) for name in extra): + if isinstance(extra, (list, tuple, np.ndarray)) and all(isinstance(name, str) for name in extra): #if extra is a list and all elements in extra are of type str for name in extra: if name in reserved: @@ -543,14 +543,6 @@ def __init__(self, phase, shape=(0,), states=None, extra=None): raise ValueError("Unable to map extra SolutionArray" "input for named {!r}".format(name)) - elif extra and sum(self._shape) == 0: - for name in extra: - if name in reserved: - raise ValueError( - "Unable to create extra column '{}': name is already " - "used by SolutionArray objects.".format(name)) - self._extra[name] = np.array([]) - elif extra: raise ValueError("Initial values for extra properties must be" " supplied in a dict or can be initialised with the property string" diff --git a/interfaces/cython/cantera/test/test_thermo.py b/interfaces/cython/cantera/test/test_thermo.py index 821d928b993..44df5e62bd6 100644 --- a/interfaces/cython/cantera/test/test_thermo.py +++ b/interfaces/cython/cantera/test/test_thermo.py @@ -1644,36 +1644,36 @@ def test_slicing_ndim(self): def test_extra(self): with self.assertRaises(ValueError): states = ct.SolutionArray(self.gas, extra=['creation_rates']) - states = ct.SolutionArray(self.gas, shape=(0,0), extra=("prop1")) - self.assertEqual(states.prop1.shape,(0,0)) + states = ct.SolutionArray(self.gas, shape=(0, 0), extra=("prop1")) + self.assertEqual(states.prop1.shape, (0, 0)) # test indexed operations on extra arrays - states = ct.SolutionArray(self.gas, 7, extra={'n': range(7)}) + states = ct.SolutionArray(self.gas, 7, extra={'prop': range(7)}) array = np.array(range(7)) - self.assertArrayNear(states.n , array) - states.n[1] = -5 - states.n[3:5] = [0,1] - array_mod = np.array([ 0, -5, 2, 0, 1, 5, 6]) - self.assertArrayNear(states.n ,array_mod) + self.assertArrayNear(states.prop, array) + states.prop[1] = -5 + states.prop[3:5] = [0, 1] + array_mod = np.array([0, -5, 2, 0, 1, 5, 6]) + self.assertArrayNear(states.prop, array_mod) #test initialaisation of extra when a list is passed - states = ct.SolutionArray(self.gas, shape=(5,9), extra=["prop1","prop2"]) - self.assertEqual(states.prop1.shape,(5,9)) - states1 = ct.SolutionArray(self.gas, shape=(0,0,0), extra="prop1") - self.assertEqual(states1.prop1.shape,(0,0,0)) + states = ct.SolutionArray(self.gas, shape=(5, 9), extra=["prop1", "prop2"]) + self.assertEqual(states.prop1.shape, (5, 9)) + states1 = ct.SolutionArray(self.gas, shape=(0, 0, 0), extra="prop1") + self.assertEqual(states1.prop1.shape, (0, 0, 0)) #test initialisation with string - states2 = ct.SolutionArray(self.gas, shape=(2,6,9), extra="prop1") - self.assertEqual(states2.prop1.shape,(2,6,9)) + states2 = ct.SolutionArray(self.gas, shape=(2, 6, 9), extra="prop1") + self.assertEqual(states2.prop1.shape, (2, 6, 9)) #test initialisation with tuples - states3 = ct.SolutionArray(self.gas, shape=(2,6,9), extra=("prop1","prop2","prop3")) - self.assertEqual(states3.prop3.shape,(2,6,9)) + states3 = ct.SolutionArray(self.gas, shape=(2, 6, 9), extra=("prop1", "prop2", "prop3")) + self.assertEqual(states3.prop3.shape, (2, 6, 9)) #test initialisation with numpy.ndarray - properties_array = np.array(["prop1","prop2","prop3"]) - states4 = ct.SolutionArray(self.gas, shape=(2,6,9), extra=properties_array) - self.assertEqual(states4.prop2.shape,(2,6,9)) + properties_array = np.array(["prop1", "prop2", "prop3"]) + states4 = ct.SolutionArray(self.gas, shape=(2, 6, 9), extra=properties_array) + self.assertEqual(states4.prop2.shape, (2, 6, 9)) def test_append(self):