Open bryanwweber opened 4 years ago
it is not possible to assign to slices of properties of the underlying
Solution
. This is inconsistent, and should either be possible or raise a useful error message. Right now, it just fails silently:
I was going to write that there was no way to make the return value immutable, but it turns out that you actually can (more or less) - https://stackoverflow.com/questions/5541324/immutable-numpy-array. It would probably make sense to set this flag on arrays returned by Solution
as well as SolutionArray
, e.g. gas.molecular_weights
and gas.net_production_rates
.
I don't think there are any cases where making properties mutable in this direction makes sense -- we don't normally allow single properties like T
to be set, and the property pairs return tuples which can't be set this way, but can be set using states[i].TP = ...
.
When appending a state, an item of length greater than 1 can be passed for any extra items.
This seems like an ordinary bug, so maybe it would be better to track that as an Issue on the main repository.
It would useful to be able to append more than one state at a time, but this isn't possible:
By analogy with the methods on the list
type, I would suggest that the append
method is used for adding one element, and extend
is used for adding multiple elements.
it turns out that you actually can (more or less)... I don't think there are any cases where making properties mutable in this direction makes sense
I agree. I'll make a new enhancements issue for this since it is broader than just SolutionArray
s, see #58.
This seems like an ordinary bug, so maybe it would be better to track that as an Issue on the main repository.
I wasn't sure, since someone could hypothetically want a sequence of some sort embedded in the array. But since it raises a DeprecationWarning
it probably shouldn't be allowed, so I'll file an issue on Cantera/cantera as a bug, see Cantera/cantera#895
By analogy with the methods on the
list
type, I would suggest that theappend
method is used for adding one element, andextend
is used for adding multiple elements.
On the other hand, np.append()
allows appending one or multiple rows to the array. Since this is called SolutionArray
, I wonder whether we should follow the convention of NumPy? I don't have a strong opinion.
I've focused this enhancement issue on just this last point.
On the other hand,
np.append()
allows appending one or multiple rows to the array. Since this is calledSolutionArray
, I wonder whether we should follow the convention of NumPy? I don't have a strong opinion.
The syntax for np.append
requires the appended items to always be list-like, though (or I guess more precisely, have all but one dimension equal to the initial array). For example, to append a single item, you have to write np.append([1,2,3], [4])
rather than np.append([1,2,3], 4)
. Since SolutionArray.append
already supports adding a scalar, I think it makes sense for a method that appends an array to have a different name. In part, that would hopefully limit the amount of guessing that has to be done based on the shape of the input data.
That makes sense, especially the part about reducing the amount of guessing about shape that has to be done :+1:
Abstract
In the course of working on Cantera/cantera#838, I found a few edge cases where the
SolutionArray
interface might be able to be improved.Problem Descriptions
When Cantera/cantera#838 is merged, it will be possible to assign to slices of extra items. However, it is not possible to assign to slices of properties of the underlying
Solution
. This is inconsistent, and should either be possible or raise a useful error message. Right now, it just fails silently:Moved to #58.
When appending a state, 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:
Yes, that's a list as an item in a NumPy array. Note the first three elements (
101325.000...
) are garbage data that was available at the memory address thatnp.empty()
used to create the array forprop
. Moved to Cantera/cantera#895.It would useful to be able to append more than one state at a time, but this isn't possible:
References
Cantera/cantera#838