dataframe-textual 2.27.0__tar.gz → 2.28.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataframe-textual
3
- Version: 2.27.0
3
+ Version: 2.28.0
4
4
  Summary: Interactive terminal viewer/editor for tabular data
5
5
  Project-URL: Homepage, https://github.com/need47/dataframe-textual
6
6
  Project-URL: Repository, https://github.com/need47/dataframe-textual.git
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataframe-textual"
7
- version = "2.27.0"
7
+ version = "2.28.0"
8
8
  description = "Interactive terminal viewer/editor for tabular data"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -9,6 +9,7 @@ from functools import partial
9
9
 
10
10
  import polars as pl
11
11
  from rich.text import Text
12
+ from textual import work
12
13
  from textual.app import ComposeResult
13
14
  from textual.coordinate import Coordinate
14
15
  from textual.renderables.bar import Bar
@@ -33,9 +34,11 @@ class TableScreen(ModalScreen):
33
34
 
34
35
  TableScreen > DataTable {
35
36
  width: auto;
37
+ max-width: 100%;
36
38
  height: auto;
39
+ min-width: 20; /* for LoadIndicator */
40
+ min-height: 3; /* for LoadIndicator */
37
41
  border: solid $primary;
38
- max-width: 100%;
39
42
  overflow: auto;
40
43
  }
41
44
  """
@@ -288,11 +291,23 @@ class StatisticsScreen(TableScreen):
288
291
  def __init__(self, dftable: "DataFrameTable", cidx: int | None = None):
289
292
  super().__init__(dftable)
290
293
  self.cidx = cidx # None for dataframe statistics, otherwise column index
291
- self.df = self.build_df()
294
+ self.df: pl.DataFrame = None
292
295
 
293
296
  def on_mount(self) -> None:
294
297
  """Create the statistics table."""
298
+ self.table.loading = True
299
+ self.calculate_statistics()
300
+
301
+ @work(thread=True)
302
+ def calculate_statistics(self) -> None:
303
+ """Calculate statistics in a background thread."""
304
+ self.df = self.build_df()
305
+ self.app.call_from_thread(self._on_calculation_ready)
306
+
307
+ def _on_calculation_ready(self) -> None:
295
308
  self.build_table()
309
+ self.table.loading = False
310
+ self.table.focus()
296
311
 
297
312
  def build_table(self) -> None:
298
313
  """Build the statistics table."""
@@ -417,13 +432,23 @@ class FrequencyScreen(TableScreen):
417
432
  self.cidx = cidx
418
433
  self.sorted_columns = {1: True} # Count sort by default
419
434
  self.total_count = len(dftable.df)
420
-
421
- col = dftable.df.columns[self.cidx]
422
- self.df: pl.DataFrame = dftable.df.lazy().select(pl.col(col).value_counts(sort=True)).unnest(col).collect()
435
+ self.df: pl.DataFrame = None
423
436
 
424
437
  def on_mount(self) -> None:
425
- """Create the frequency table."""
438
+ """Start frequency calculation."""
439
+ self.table.loading = True
440
+ self.calculate_frequency()
441
+
442
+ @work(thread=True)
443
+ def calculate_frequency(self) -> None:
444
+ col = self.dftable.df.columns[self.cidx]
445
+ self.df = self.dftable.df.lazy().select(pl.col(col).value_counts(sort=True)).unnest(col).collect()
446
+ self.app.call_from_thread(self._on_calculation_ready)
447
+
448
+ def _on_calculation_ready(self) -> None:
426
449
  self.build_table()
450
+ self.table.loading = False
451
+ self.table.focus()
427
452
 
428
453
  def on_key(self, event):
429
454
  if event.key == "left_square_bracket": # '['
@@ -35,8 +35,7 @@ class ThemeScreen(ModalScreen):
35
35
  def __init__(self) -> None:
36
36
  super().__init__()
37
37
  self.themes = list(BUILTIN_THEMES.keys())
38
- self.original_theme = ""
39
- self._confirmed = False
38
+ self.original_theme = self.app.theme
40
39
 
41
40
  def compose(self) -> ComposeResult:
42
41
  with Container(id="theme-container") as container:
@@ -44,28 +43,22 @@ class ThemeScreen(ModalScreen):
44
43
  yield OptionList(*self.themes, id="theme-list")
45
44
 
46
45
  def on_mount(self) -> None:
47
- self.original_theme = self.app.theme
48
46
  options = self.query_one(OptionList)
49
47
  if self.original_theme in self.themes:
50
48
  options.highlighted = self.themes.index(self.original_theme)
51
49
  options.focus()
52
50
 
53
51
  def _set_theme(self, theme: str) -> None:
54
- if theme in BUILTIN_THEMES:
52
+ if theme in self.themes:
55
53
  self.app.theme = theme
56
54
 
57
55
  def on_option_list_option_highlighted(self, event: OptionList.OptionHighlighted) -> None:
58
56
  self._set_theme(str(event.option.prompt))
59
57
 
60
58
  def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
61
- self._confirmed = True
62
59
  self._set_theme(str(event.option.prompt))
63
60
  self.app.pop_screen()
64
61
 
65
62
  def action_cancel(self) -> None:
66
63
  self.app.theme = self.original_theme
67
64
  self.app.pop_screen()
68
-
69
- def on_unmount(self) -> None:
70
- if not self._confirmed:
71
- self.app.theme = self.original_theme
@@ -171,7 +171,7 @@ wheels = [
171
171
 
172
172
  [[package]]
173
173
  name = "dataframe-textual"
174
- version = "2.27.0"
174
+ version = "2.28.0"
175
175
  source = { editable = "." }
176
176
  dependencies = [
177
177
  { name = "fastexcel" },