Skip to content

Commit

Permalink
[thermo] Prevent creation of pre-existing extra SolutionArray columns
Browse files Browse the repository at this point in the history
SolutionArray objects inherit properties from Solution objects, which will mask
newly defined 'extra' columns. This commit prevents the creation of homonymous
extra columns.
  • Loading branch information
ischoegl authored and speth committed Mar 23, 2020
1 parent 712a6bf commit 506ef6f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions interfaces/cython/cantera/composite.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,15 @@ def __init__(self, phase, shape=(0,), states=None, extra=None):
self._indices = list(np.ndindex(self._shape))
self._output_dummy = self._states[..., 0]

reserved = self.__dir__()

self._extra = {}
if isinstance(extra, dict):
for name, v in extra.items():
if name in reserved:
raise ValueError(
"Unable to create extra column '{}': name is already "
"used by SolutionArray objects.".format(name))
if not np.shape(v):
self._extra[name] = [v]*self._shape[0]
elif len(v) == self._shape[0]:
Expand All @@ -526,6 +532,10 @@ def __init__(self, phase, shape=(0,), states=None, extra=None):

elif extra and 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] = []

elif extra:
Expand Down

0 comments on commit 506ef6f

Please sign in to comment.