Skip to content
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

Merged
merged 10 commits into from
Aug 14, 2024
Merged

Conversation

p-snft
Copy link
Member

@p-snft p-snft commented Aug 12, 2024

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.

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().
@p-snft
Copy link
Member Author

p-snft commented Aug 12, 2024

  • Fix: solph.processing still expects the auto-stretching to have happened.
  • Add tests for new sequence class.

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.
@pep8speaks
Copy link

pep8speaks commented Aug 12, 2024

Hello @p-snft! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2024-08-13 08:31:19 UTC

tests/test_plumbing.py Fixed Show fixed Hide fixed
tests/test_plumbing.py Fixed Show fixed Hide fixed
tests/test_plumbing.py Fixed Show fixed Hide fixed
@p-snft p-snft self-assigned this Aug 12, 2024
@p-snft p-snft added this to the v0.5.x milestone Aug 12, 2024
@uvchik
Copy link
Member

uvchik commented Aug 13, 2024

TODO: solph.processing still expects the auto-stretching to have happened.

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.

@p-snft
Copy link
Member Author

p-snft commented Aug 13, 2024

TODO: solph.processing still expects the auto-stretching to have happened.

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).

@p-snft p-snft marked this pull request as ready for review August 13, 2024 08:28
@p-snft p-snft requested a review from uvchik August 13, 2024 08:31
Copy link
Member

@uvchik uvchik left a 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.

@uvchik uvchik merged commit a73941f into dev Aug 14, 2024
14 checks passed
@uvchik uvchik deleted the revision/simplified_fake_sequence branch August 14, 2024 19:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Chained sequence yields unexpected result
3 participants