-
-
Notifications
You must be signed in to change notification settings - Fork 346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Slicing of SolutionArray raises error #804
Comments
@ischoegl I am new and wish to contribute to Cantera learning about its codebase kindly review my PR |
Interestingly, a zero-length slice still raises an error even after #816 is merged: In [8]: import cantera as ct
In [9]: gas = ct.Solution('gri30.yaml')
In [10]: arr = ct.SolutionArray(gas, 10)
In [11]: arr[slice(0)]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-11-95d215c2766e> in <module>
----> 1 arr[slice(0)]
~/GitHub/cantera/build/python/cantera/composite.py in __getitem__(self, index)
548 if(isinstance(states, list)):
549 num_rows = len(states)
--> 550 return SolutionArray(self._phase, num_rows, states)
551 else:
552 shape = states.shape[:-1]
~/GitHub/cantera/build/python/cantera/composite.py in __init__(self, phase, shape, states, extra)
512 else:
513 self._indices = list(np.ndindex(self._shape))
--> 514 self._output_dummy = self._states[..., 0]
515
516 reserved = self.__dir__()
TypeError: list indices must be integers or slices, not tuple whereas that returns a zero-length list/array for a plain Python list and a NumPy array. So I think there is one more edge case to handle here. |
@bryanwweber / @sin-ha ... didn’t anticipate this one either: good catch. |
the problem extends for this case too i.e. for all arr[x:x]
The problem exists in basic handling of shapes in the init class where the |
System information
Expected behavior
Slicing of
SolutionArray
objects should work as usual (as indexing is implemented).Actual behavior
Slicing does not work.
To Reproduce
Steps to reproduce the behavior:
Additional context
The error message clearly points at the issue.
The text was updated successfully, but these errors were encountered: