Skip to content

Sequences can be appended as extra items on a SolutionArray #895

@bryanwweber

Description

@bryanwweber

When appending a state to a SolutionArray, an item of length greater than 1 can be passed for any extra items. This raises a DeprecationWarning from NumPy, and gives a... less than useful result:

>>> gas = ct.Solution("air.yaml")
>>> states = ct.SolutionArray(gas, 3, extra={"prop": [5, 6, 7]}
>>> states.append(TPX=(1100, 3e5, "AR:1.0"), prop=[1, 2, 3])
>>> states.prop
/Users/bryan/GitHub/cantera/build/python/cantera/composite.py:576: VisibleDeprecationWarning:
Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays
with different lengths or shapes) is deprecated. If you meant to do this, you must specify 
'dtype=object' when creating the ndarray
  return np.array(self._extra[name])
array([5, 6, 7, list([1, 2, 3])], dtype=object)

Yes, that's a list as an item in a NumPy array.

Fixing this is not super straightforward, because we may need to also account for the possibility of strings as values, so a simple if len(item) > 1 check is not sufficient, see #896.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions