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

Sparklines do not work with collections.deque #3899

Closed
rhacer63 opened this issue Dec 18, 2023 · 7 comments · Fixed by #4196
Closed

Sparklines do not work with collections.deque #3899

rhacer63 opened this issue Dec 18, 2023 · 7 comments · Fixed by #4196
Assignees
Labels
bug Something isn't working

Comments

@rhacer63
Copy link

from collections import deque

from textual.app import App, ComposeResult
from textual.widgets import Sparkline

data = deque([1, 2, 2, 1, 1, 4, 3, 1, 1, 8, 8, 2])


class SparklineBasicApp(App[None]):
    def compose(self) -> ComposeResult:
        yield Sparkline(
            data,
            summary_function=max,
        )


app = SparklineBasicApp()
if __name__ == "__main__":
    app.run()

I was working on creating a scrolling Sparkline and ran into this problem. When using a deque as the data element for a Sparkline you receive a TypeError: sequence index must be integer, not 'slice' exception.

@Textualize Textualize deleted a comment from github-actions bot Dec 19, 2023
@rodrigogiraoserrao rodrigogiraoserrao added the bug Something isn't working label Dec 19, 2023
@rodrigogiraoserrao
Copy link
Contributor

Hey, thanks for raising this issue.

As a temporary workaround, which you probably thought of already, you can create the sparkline with Sparkline(list(data), ...).

@willmcgugan
Copy link
Collaborator

Seems to be a typing issue. A Sequence should accept a slice according to the docs.

@rodrigogiraoserrao
Copy link
Contributor

In conclusion, issubclass(deque, Sequence) should return False, right?
In that case, we can close this issue, right?

@rhacer63
Copy link
Author

Hey, thanks for raising this issue.

As a temporary workaround, which you probably thought of already, you can create the sparkline with Sparkline(list(data), ...).

I, of course, had not already thought of that, though I would have gotten there eventually! Thank you very much.

@rodrigogiraoserrao
Copy link
Contributor

Opened the bug report python/cpython#113313 to track the underlying issue.

@willmcgugan
Copy link
Collaborator

So it looks like the Python devs have refined the definition of Sequence to not include slices.

We should look in to updating the typing, or make it work without slices if at all possible.

@davep davep self-assigned this Feb 20, 2024
davep added a commit to davep/textual that referenced this issue Feb 21, 2024
davep added a commit to davep/textual that referenced this issue Feb 21, 2024
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants