Skip to content

Commit

Permalink
POC: inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaramadze committed Jan 22, 2025
1 parent fa6a496 commit c68503e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
49 changes: 49 additions & 0 deletions quixstreams/dataframe/dataframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,55 @@ def print(self, pretty: bool = True, metadata: bool = False) -> Self:
metadata=metadata,
)

def inspect(self, number: int = 10, maxlen: int = 30) -> Self:
"""
Creates an interactive debugging session that displays each value
in a formatted Textual table.
Controls:
- Press 'c' to continue to next value
- Press 'q' to quit completely (exits Python)
"""
assert maxlen >= number # noqa

import sys
from collections import deque

from textual.app import App
from textual.containers import Container
from textual.widgets import DataTable, Footer

class Inspector(App):
def __init__(self, messages: deque):
super().__init__()
self.messages = messages
self.table = DataTable()

def compose(self):
yield Container(self.table)
yield Footer()

def on_mount(self):
self.table.add_columns("Key", "Timestamp", "Value", "Headers")
for value, key, timestamp, headers in self.messages:
self.table.add_row(key, timestamp, value, headers)

def on_key(self, event):
if event.key == "c":
self.exit()
elif event.key == "q":
sys.exit(0)

messages: deque = deque(maxlen=maxlen)

def _inspect(value, key, timestamp, headers):
messages.append((value, key, timestamp, headers))
if len(messages) >= number:
app = Inspector(messages)
app.run()

return self._add_update(_inspect, metadata=True)

def compose(
self,
sink: Optional[Callable[[Any, Any, int, Any], None]] = None,
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pre-commit>=3.4,<4.1
textual-dev
-r requirements-mypy.txt
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ pydantic>=2.7,<2.11
pydantic-settings>=2.3,<2.7
jsonschema>=4.3.0
jsonlines>=4,<5
textual

0 comments on commit c68503e

Please sign in to comment.