-
Notifications
You must be signed in to change notification settings - Fork 132
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
Replace _Sequence by _FakeSequence #1101
Conversation
The auto-stretch feature of the _Sequence contained hidden magic, as it tracked the last "entry" that has been accessed and pretended to have a length based on this. So, outcomes depend on something that is assumed to be a read access. Also, self.data was erived from UserList but never really supported all of the expected functionality in a consistent way. The new _FakeSequence is a lot simpler. In particular it has an explicit (fake) length that needs to be set before casting to (stretched) lists. The default length is still set, because there is an entry, and to allow to directly iterate over a _FakeSequence, e.g. in sum().
|
To allow this, some checks need to more explicit, now. As solph.sequence will return a _FakeSequence or a numpy.array, other members of _FakeSequence mimic the API of numpy.array. In particular, this allows min/max/sum operations in constant time.
We can test for the _FakeSequence class to see that something really is a scalar.
Where is auto-stretching needed and why are all tests fine? I would expect a failing test that will be fine if we have fixed that issue. |
I fixed that already (in 3e94ccc). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine to me and in my opinion things are clearer now.
The auto-stretch feature of the _Sequence contained hidden magic, as it tracked the last "entry" that has been accessed and pretended to have a length based on this. So, outcomes depend on something that is assumed to be a read access. Also, self.data was erived from UserList but never really supported all of the expected functionality in a consistent way.
The new _FakeSequence is a lot simpler. In particular it has an explicit (fake) length that needs to be set before casting to (stretched) lists. The default length is not set, because member functions using the same names as in
numpy.array
can help to work without an iterator.Fixes #1100.