dataframe-textual 3.1.1__tar.gz → 3.1.3__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.
Files changed (24) hide show
  1. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/PKG-INFO +2 -2
  2. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/pyproject.toml +1 -1
  3. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/common.py +6 -6
  4. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/data_frame_table.py +179 -182
  5. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/table_screen.py +10 -10
  6. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/yes_no_screen.py +13 -2
  7. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/uv.lock +1 -1
  8. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/.gitignore +0 -0
  9. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/LICENSE +0 -0
  10. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/README.md +0 -0
  11. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/main.py +0 -0
  12. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/__init__.py +0 -0
  13. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/__main__.py +0 -0
  14. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/commands.py +0 -0
  15. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/console_panel.py +0 -0
  16. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/data_frame_viewer.py +0 -0
  17. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/file_picker_screen.py +0 -0
  18. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/help_panel.py +0 -0
  19. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/keybindings.py +0 -0
  20. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/loading_screen.py +0 -0
  21. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/run_command_screen.py +0 -0
  22. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/status_bar.py +0 -0
  23. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/text_screen.py +0 -0
  24. {dataframe_textual-3.1.1 → dataframe_textual-3.1.3}/src/dataframe_textual/theme_screen.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: dataframe-textual
3
- Version: 3.1.1
3
+ Version: 3.1.3
4
4
  Summary: Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc.
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 = "3.1.1"
7
+ version = "3.1.3"
8
8
  description = "Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -60,22 +60,22 @@ BAR_COLUMN_WIDTH = 10
60
60
  THOUSAND_SEPARATOR = ","
61
61
 
62
62
 
63
- def format_float(value: float, thousand_separator: bool = False, precision: int = 2) -> str:
63
+ def format_float(value: float, thousand_separator: bool = False, precision: int = -1) -> str:
64
64
  """Format a float value, keeping integers without decimal point.
65
65
 
66
66
  Args:
67
67
  value: The float value to format.
68
68
  thousand_separator: Whether to include thousand separators. Defaults to False.
69
- precision: The number of decimal places to display. Defaults to 2.
69
+ precision: The number of decimal places to display. Defaults to -1 (no rounding).
70
70
 
71
71
  Returns:
72
72
  The formatted float as a string.
73
73
  """
74
74
 
75
- if precision == 0 and (value_int := int(value)) == value:
75
+ if precision == -1 and (value_int := int(value)) == value:
76
76
  return f"{value_int:{THOUSAND_SEPARATOR}}" if thousand_separator else str(value_int)
77
77
  else:
78
- if precision > 0:
78
+ if precision > -1:
79
79
  return f"{value:{THOUSAND_SEPARATOR}.{precision}f}" if thousand_separator else f"{value:.{precision}f}"
80
80
  else:
81
81
  return f"{value:{THOUSAND_SEPARATOR}f}" if thousand_separator else str(value)
@@ -274,7 +274,7 @@ def format_row(
274
274
  style: str | list[str] | None = None,
275
275
  justify: str | list[str] | None = None,
276
276
  thousand_separator: bool | list[bool] = False,
277
- float_precision: int | list[int] = 2,
277
+ float_precision: int | list[int] = -1,
278
278
  ) -> list[Text]:
279
279
  """Format a single row with proper styling and justification.
280
280
 
@@ -289,7 +289,7 @@ def format_row(
289
289
  thousand_separator: Whether to include thousand separators for numeric values.
290
290
  Can be a single bool (applied to all) or a list of bools per column. Defaults to False.
291
291
  float_precision: Number of decimal places for float values.
292
- Can be a single int (applied to all) or a list of ints per column. Defaults to 2.
292
+ Can be a single int (applied to all) or a list of ints per column. Defaults to -1 (no rounding).
293
293
 
294
294
  Returns:
295
295
  A list of Rich Text objects with proper formatting applied.
@@ -259,7 +259,7 @@ class DataFrameTable(DataTable):
259
259
  # Per-column float precision: col_name -> number of decimal places
260
260
  self.float_precision_columns: dict[str, int] = {}
261
261
 
262
- # Per-column width overrides: col_name -> display width
262
+ # Per-column width overrides: col_name -> display width (-1 indicates expanded width)
263
263
  self.column_widths: dict[str, int] = {}
264
264
 
265
265
  # Columns displaying as inline bar charts
@@ -669,11 +669,6 @@ class DataFrameTable(DataTable):
669
669
  """Get columns hidden through the column width state."""
670
670
  return {col for col, width in self.column_widths.items() if width == 0}
671
671
 
672
- @property
673
- def expanded_columns(self) -> set[str]:
674
- """Get columns expanded through the column width state."""
675
- return {col for col, width in self.column_widths.items() if width == -1}
676
-
677
672
  @property
678
673
  def ordered_selected_rows(self) -> list[int]:
679
674
  """Get the list of selected row indices in order.
@@ -1024,19 +1019,19 @@ class DataFrameTable(DataTable):
1024
1019
 
1025
1020
  def cmd_find_forward_all(self) -> None:
1026
1021
  """Search forward in all columns with expression."""
1027
- self.cmd_find_forward(forward=True, scope="all")
1022
+ self._find_value(forward=True, scope="all")
1028
1023
 
1029
1024
  def cmd_find_forward_cursor(self) -> None:
1030
1025
  """Search forward in current column with cursor value."""
1031
- self._find_cursor_direct(forward=True, scope="column")
1026
+ self._find_cursor(forward=True, scope="column")
1032
1027
 
1033
1028
  def cmd_find_backward_all(self) -> None:
1034
1029
  """Search backward in all columns with expression."""
1035
- self.cmd_find_backward(forward=False, scope="all")
1030
+ self._find_value(forward=False, scope="all")
1036
1031
 
1037
1032
  def cmd_find_backward_cursor(self) -> None:
1038
1033
  """Search backward in current column with cursor value."""
1039
- self._find_cursor_direct(forward=False, scope="column")
1034
+ self._find_cursor(forward=False, scope="column")
1040
1035
 
1041
1036
  def cmd_replace_column(self) -> None:
1042
1037
  """Replace in current column."""
@@ -1177,6 +1172,8 @@ class DataFrameTable(DataTable):
1177
1172
  def cmd_toggle_thousand_separator(self) -> None:
1178
1173
  """Toggle thousand separator for the current cursor column."""
1179
1174
  col_name = self.cursor_col_name
1175
+ self.add_history(f"Toggle thousand separator for column [$accent]{col_name}[/]")
1176
+
1180
1177
  if col_name in self.thousand_separator_columns:
1181
1178
  self.thousand_separator_columns.discard(col_name)
1182
1179
  status = "off"
@@ -1193,6 +1190,7 @@ class DataFrameTable(DataTable):
1193
1190
  severity="warning",
1194
1191
  )
1195
1192
  return
1193
+
1196
1194
  self.setup_table()
1197
1195
  self.notify(
1198
1196
  f"Thousand separator is [$success]{status}[/] for column [$accent]{col_name}[/]",
@@ -1208,7 +1206,11 @@ class DataFrameTable(DataTable):
1208
1206
  self._adjust_float_precision(1)
1209
1207
 
1210
1208
  def _adjust_float_precision(self, delta: int) -> None:
1211
- """Adjust float precision for the current cursor column."""
1209
+ """Adjust float precision for the current cursor column.
1210
+
1211
+ Args:
1212
+ delta: The change in precision (positive to increase, negative to decrease).
1213
+ """
1212
1214
  col_name = self.cursor_col_name
1213
1215
  dtype = self.cursor_col_dtype
1214
1216
  dc = DtypeConfig(dtype)
@@ -1219,26 +1221,59 @@ class DataFrameTable(DataTable):
1219
1221
  severity="warning",
1220
1222
  )
1221
1223
  return
1222
- current = self.float_precision_columns.get(col_name, 0)
1223
- new_precision = max(0, current + delta)
1224
- if new_precision == 0:
1224
+
1225
+ self.add_history(f"Adjust float precision for column [$success]{col_name}[/] by [$accent]{delta}[/]")
1226
+
1227
+ # Start from the current precision (default: 2), apply delta,
1228
+ # and clamp at -1 where -1 means precision formatting is turned off.
1229
+ current = self.float_precision_columns.get(col_name, 2)
1230
+ new_precision = max(-1, current + delta)
1231
+ if new_precision == -1:
1225
1232
  self.float_precision_columns.pop(col_name, None)
1226
1233
  else:
1227
1234
  self.float_precision_columns[col_name] = new_precision
1235
+
1228
1236
  if new_precision != current:
1229
1237
  self.setup_table()
1238
+
1230
1239
  message = (
1231
1240
  f"Float precision turned [$success]off[/] for column [$accent]{col_name}[/]"
1232
- if new_precision == 0
1241
+ if new_precision == -1
1233
1242
  else f"Float precision for column [$success]{col_name}[/] set to [$accent]{new_precision}[/] decimal place(s)"
1234
1243
  )
1235
1244
  self.notify(message, title="Set Float Precision")
1236
1245
 
1246
+ def _build_column_label(self, col_name: str, visible_col_idx: int | None = None) -> str:
1247
+ """Build display label for a column header.
1248
+
1249
+ Args:
1250
+ col_name: Source dataframe column name.
1251
+ visible_col_idx: 1-based index of the column among visible columns.
1252
+
1253
+ Returns:
1254
+ Column label text with optional index prefix and sort indicator.
1255
+ """
1256
+ label = col_name
1257
+ if self.show_column_index:
1258
+ label = f"{visible_col_idx or self.cursor_column + 1}_{label}"
1259
+
1260
+ for idx, c in enumerate(self.sorted_columns, 1):
1261
+ if c == col_name:
1262
+ # Add sort indicator to column header
1263
+ descending = self.sorted_columns[col_name]
1264
+ sort_indicator = (
1265
+ f" ▼{SUBSCRIPT_DIGITS.get(idx, '')}" if descending else f" ▲{SUBSCRIPT_DIGITS.get(idx, '')}"
1266
+ )
1267
+ label = col_name + sort_indicator
1268
+ break
1269
+
1270
+ return label
1271
+
1237
1272
  def _column_label_width(self, col_name: str) -> int:
1238
1273
  """Measure the display width needed for a column label."""
1239
1274
  visible_col_idx = list(self.visible_columns).index(col_name) + 1
1240
1275
  label = self._build_column_label(col_name, visible_col_idx)
1241
- return measure(self.app.console, label, 1) + 2
1276
+ return measure(self.app.console, label, 1)
1242
1277
 
1243
1278
  def resize_column(self, col_name: str, result: str | None) -> None:
1244
1279
  """Set the display width for a column from user input.
@@ -1361,10 +1396,9 @@ class DataFrameTable(DataTable):
1361
1396
  sample_lf = self.df.lazy().head(sample_size)
1362
1397
 
1363
1398
  # ── Phase 1: initial width for every visible column ───────────────────
1364
- for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
1399
+ for col, dtype in self.visible_columns.items():
1365
1400
  # Label width is the hard minimum
1366
- label_text = self._build_column_label(col, col_idx)
1367
- label_width = measure(self.app.console, label_text, 1)
1401
+ label_width = self._column_label_width(col)
1368
1402
  col_label_widths[col] = label_width
1369
1403
 
1370
1404
  # Bar columns: already fixed
@@ -1466,38 +1500,12 @@ class DataFrameTable(DataTable):
1466
1500
 
1467
1501
  # Add columns with justified headers
1468
1502
  for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
1469
- cell_value = self._build_column_label(col, col_idx)
1503
+ label = self._build_column_label(col, col_idx)
1470
1504
 
1471
1505
  # Get the width for this column (None means auto-size)
1472
1506
  width = column_widths.get(col)
1473
1507
 
1474
- self.add_column(Text(cell_value, justify=DtypeConfig(dtype).justify), key=col, width=width)
1475
-
1476
- def _build_column_label(self, col_name: str, visible_col_idx: int | None = None) -> str:
1477
- """Build display label for a column header.
1478
-
1479
- Args:
1480
- col_name: Source dataframe column name.
1481
- visible_col_idx: 1-based index of the column among visible columns.
1482
-
1483
- Returns:
1484
- Column label text with optional index prefix and sort indicator.
1485
- """
1486
- label = col_name
1487
- if self.show_column_index:
1488
- label = f"{visible_col_idx or self.cursor_column + 1}_{label}"
1489
-
1490
- for idx, c in enumerate(self.sorted_columns, 1):
1491
- if c == col_name:
1492
- # Add sort indicator to column header
1493
- descending = self.sorted_columns[col_name]
1494
- sort_indicator = (
1495
- f" ▼{SUBSCRIPT_DIGITS.get(idx, '')}" if descending else f" ▲{SUBSCRIPT_DIGITS.get(idx, '')}"
1496
- )
1497
- label = col_name + sort_indicator
1498
- break
1499
-
1500
- return label
1508
+ self.add_column(Text(label, justify=DtypeConfig(dtype).justify), key=col, width=width)
1501
1509
 
1502
1510
  def _calculate_load_range(self, start: int, stop: int) -> list[tuple[int, int]]:
1503
1511
  """Calculate the actual ranges to load, accounting for already-loaded ranges.
@@ -1679,7 +1687,7 @@ class DataFrameTable(DataTable):
1679
1687
  # Load the dataframe slice
1680
1688
  df_slice = self.df.slice(segment_start, segment_stop - segment_start)
1681
1689
  thousand_separator = [col in self.thousand_separator_columns for col in visible_columns]
1682
- float_precision = [self.float_precision_columns.get(col, 0) for col in visible_columns]
1690
+ float_precision = [self.float_precision_columns.get(col, -1) for col in visible_columns]
1683
1691
 
1684
1692
  # Load each row at the correct position
1685
1693
  for (ridx, row), rid in zip(enumerate(df_slice.iter_rows(), segment_start), df_slice[RID]):
@@ -2255,6 +2263,8 @@ class DataFrameTable(DataTable):
2255
2263
  )
2256
2264
  return
2257
2265
 
2266
+ self.add_history(f"Toggle bar chart for column [$accent]{col_name}[/]", dirty=False)
2267
+
2258
2268
  # Toggle bar display
2259
2269
  if col_name in self.bar_columns:
2260
2270
  self.bar_columns.discard(col_name)
@@ -2292,7 +2302,9 @@ class DataFrameTable(DataTable):
2292
2302
  def cmd_toggle_freeze(self) -> None:
2293
2303
  """Toggle the freeze."""
2294
2304
  if self.fixed_rows or self.fixed_columns:
2305
+ self.add_history("Unfreeze all rows and columns")
2295
2306
  self.fixed_rows = self.fixed_columns = 0
2307
+ self.setup_table()
2296
2308
  self.notify("Unfreezed all rows and columns", title="Freeze Row/Column")
2297
2309
  else:
2298
2310
  self.app.push_screen(FreezeScreen(), callback=self.toggle_freeze_row_column)
@@ -2387,11 +2399,11 @@ class DataFrameTable(DataTable):
2387
2399
  return None
2388
2400
  col: Column = self.columns[col_key]
2389
2401
 
2390
- label_width = len(self._build_column_label(col_name)) + 2
2402
+ label_width = self._column_label_width(col_name)
2391
2403
 
2392
2404
  # If already expanded, shrink back
2393
- if col_name in self.expanded_columns:
2394
- col.width = max(label_width, COLUMN_WIDTH_CAP)
2405
+ if self.column_widths.get(col_name) == -1:
2406
+ col.width = label_width
2395
2407
  self.column_widths.pop(col_name, None)
2396
2408
  return f"[$success]{col_name}[/] shrunk to [$accent]{col.width}[/]"
2397
2409
 
@@ -2402,7 +2414,17 @@ class DataFrameTable(DataTable):
2402
2414
 
2403
2415
  for row_start, row_end in self.loaded_ranges:
2404
2416
  for ridx in range(row_start, row_end):
2405
- cell_value = str(self.df.item(ridx, cidx))
2417
+ cell = self.df.item(ridx, cidx)
2418
+ if cell is None:
2419
+ # Null cells render as the null placeholder, not "None".
2420
+ cell_value = NULL_DISPLAY
2421
+ elif isinstance(cell, pl.Series):
2422
+ # Polars returns list scalars as a Series; measure the
2423
+ # compact list text that is actually shown in the cell.
2424
+ cell_value = str(cell.to_list())
2425
+ else:
2426
+ cell_value = str(cell)
2427
+
2406
2428
  cell_width = measure(self.app.console, cell_value, 1)
2407
2429
  if cell_width > new_width:
2408
2430
  need_expand = True
@@ -2411,7 +2433,7 @@ class DataFrameTable(DataTable):
2411
2433
  if not need_expand:
2412
2434
  return None
2413
2435
 
2414
- self.column_widths[col_name] = -1
2436
+ self.column_widths[col_name] = -1 # Mark as expanded
2415
2437
  col.width = new_width
2416
2438
  return f"[$success]{col_name}[/] expanded to [$accent]{new_width}[/]"
2417
2439
 
@@ -2437,8 +2459,7 @@ class DataFrameTable(DataTable):
2437
2459
 
2438
2460
  results = []
2439
2461
  for col_name in target_cols:
2440
- result = self._expand_single_column(col_name)
2441
- if result:
2462
+ if result := self._expand_single_column(col_name):
2442
2463
  results.append(result)
2443
2464
 
2444
2465
  if not results:
@@ -2458,8 +2479,8 @@ class DataFrameTable(DataTable):
2458
2479
  return
2459
2480
 
2460
2481
  col_name = self.cursor_col_key.value
2461
- result = self._expand_single_column(col_name)
2462
- if not result:
2482
+
2483
+ if not (result := self._expand_single_column(col_name)):
2463
2484
  return
2464
2485
 
2465
2486
  self._update_count += 1
@@ -2716,7 +2737,7 @@ class DataFrameTable(DataTable):
2716
2737
 
2717
2738
  # Expand column width if new content is wider than the explicit width set during setup
2718
2739
  col = self.columns[col_key]
2719
- new_content_width = measure(self.app.console, str(display_value), 1) + 2
2740
+ new_content_width = measure(self.app.console, str(display_value), 1)
2720
2741
  if col.width is not None and new_content_width > col.width:
2721
2742
  col.width = new_content_width
2722
2743
 
@@ -2855,12 +2876,6 @@ class DataFrameTable(DataTable):
2855
2876
 
2856
2877
  col_name, new_name = result
2857
2878
  col_idx = self.get_col_idx(col_name)
2858
- if new_name is None:
2859
- self.app.push_screen(
2860
- RenameColumnScreen(col_name, self.df.columns),
2861
- callback=self.rename_column,
2862
- )
2863
- return
2864
2879
 
2865
2880
  # Add to history
2866
2881
  self.add_history(f"Rename column [$success]{col_name}[/] to [$accent]{new_name}[/]", dirty=True)
@@ -2899,6 +2914,8 @@ class DataFrameTable(DataTable):
2899
2914
 
2900
2915
  self.notify(f"Renamed column [$success]{col_name}[/] to [$accent]{new_name}[/]", title="Rename Column")
2901
2916
 
2917
+ @with_full_df
2918
+ @with_busy_screen
2902
2919
  def cmd_clear_cell(self) -> None:
2903
2920
  """Clear the current cell by setting its value to None."""
2904
2921
  row_key, col_key = self.cursor_key
@@ -2948,6 +2965,8 @@ class DataFrameTable(DataTable):
2948
2965
  )
2949
2966
  self.log(f"Error clearing cell ({ridx}, {col_name}): {e}")
2950
2967
 
2968
+ @with_full_df
2969
+ @with_busy_screen
2951
2970
  def cmd_clear_column(self) -> None:
2952
2971
  """Clear cells in the current column that match the cursor value by setting them to None."""
2953
2972
  col_idx = self.cursor_column
@@ -2985,7 +3004,7 @@ class DataFrameTable(DataTable):
2985
3004
  self.notify(f"Failed to clear column [$error]{col_name}[/]", title="Clear Column", severity="error")
2986
3005
  self.log(f"Error clearing column `{col_name}`: {e}")
2987
3006
 
2988
- def _get_column_name(self, col_name: str) -> str:
3007
+ def _new_column_name(self, col_name: str) -> str:
2989
3008
  """Get a unique column name based on the provided name."""
2990
3009
  if col_name not in self.df.columns:
2991
3010
  return col_name
@@ -2998,47 +3017,15 @@ class DataFrameTable(DataTable):
2998
3017
  new_col_name = f"{base_name}_{counter}"
2999
3018
  return new_col_name
3000
3019
 
3001
- @with_full_df
3002
3020
  def cmd_add_column(self, col_name: str | None = None) -> None:
3003
3021
  """Add acolumn after the current column."""
3004
- cidx = self.cursor_cidx
3005
-
3006
3022
  # Generate a unique column name
3007
3023
  if not col_name:
3008
- new_col_name = self._get_column_name("new_col")
3024
+ new_col_name = self._new_column_name("new_col")
3009
3025
  else:
3010
- new_col_name = col_name
3011
-
3012
- # Add to history
3013
- self.add_history(f"Add column [$success]{new_col_name}[/] after column [$accent]{cidx + 1}[/]", dirty=True)
3014
-
3015
- try:
3016
- # Create an empty column (all None values)
3017
- new_col = pl.lit(None).alias(new_col_name)
3018
-
3019
- # Get columns up to current, the new column, then remaining columns
3020
- cols = self.df.columns
3021
- cols_before = cols[: cidx + 1]
3022
- cols_after = cols[cidx + 1 :]
3023
-
3024
- # Build the new dataframe with columns reordered
3025
- select_cols = cols_before + [new_col] + cols_after
3026
- self.df = self.df.lazy().with_columns(new_col).select(select_cols).collect()
3027
-
3028
- # Also update the full datafram if applicable
3029
- if self.in_view:
3030
- self.dfull = self.dfull.lazy().with_columns(new_col).select(select_cols).collect()
3031
-
3032
- # Recreate table for display
3033
- self.setup_table()
3026
+ new_col_name = self._new_column_name(col_name)
3034
3027
 
3035
- # Move cursor to the new column
3036
- self.move_cursor(column=cidx + 1)
3037
-
3038
- self.notify(f"Added column [$success]{new_col_name}[/]", title="Add Column")
3039
- except Exception as e:
3040
- self.notify(f"Failed to add column [$error]{new_col_name}[/]", title="Add Column", severity="error")
3041
- self.log(f"Error adding column `{new_col_name}`: {e}")
3028
+ self.add_column_expr((self.cursor_col_name, new_col_name, pl.lit(None)))
3042
3029
 
3043
3030
  def cmd_add_column_expr(self) -> None:
3044
3031
  """Open screen to add a new column with optional expression."""
@@ -3095,6 +3082,7 @@ class DataFrameTable(DataTable):
3095
3082
  self.log(f"Error adding column `{new_col_name}`: {e}")
3096
3083
 
3097
3084
  @with_full_df
3085
+ @with_busy_screen
3098
3086
  def cmd_add_index_column(self, start: int = 1, step: int = 1) -> None:
3099
3087
  """Add an index column after the current column.
3100
3088
 
@@ -3103,7 +3091,7 @@ class DataFrameTable(DataTable):
3103
3091
  step: Step between values in the sequence. Defaults to 1.
3104
3092
  """
3105
3093
  cidx = self.cursor_cidx
3106
- new_col_name = self._get_column_name("index")
3094
+ new_col_name = self._new_column_name("index")
3107
3095
 
3108
3096
  # Add to history
3109
3097
  self.add_history(
@@ -3187,7 +3175,7 @@ class DataFrameTable(DataTable):
3187
3175
 
3188
3176
  cidx = self.cursor_cidx
3189
3177
  col_name = self.cursor_col_name
3190
- new_col_name = self._get_column_name(f"{col_name}_split")
3178
+ new_col_name = self._new_column_name(f"{col_name}_split")
3191
3179
 
3192
3180
  self.add_history(
3193
3181
  f"Split column [$success]{col_name}[/] into [$success]{new_col_name}[/] using delimiter [$accent]{delimiter}[/]",
@@ -3276,7 +3264,7 @@ class DataFrameTable(DataTable):
3276
3264
 
3277
3265
  cidx = self.cursor_cidx
3278
3266
  base_name = "_".join(ordered_selected)
3279
- new_col_name = self._get_column_name(base_name)
3267
+ new_col_name = self._new_column_name(base_name)
3280
3268
 
3281
3269
  self.add_history(
3282
3270
  f"Join [$accent]{len(ordered_selected)}[/] columns into [$success]{new_col_name}[/] with delimiter [$accent]{delimiter}[/]",
@@ -3339,12 +3327,12 @@ class DataFrameTable(DataTable):
3339
3327
  label=f"Enter the delimiter to join items of [$success]{col_name}[/] into a string",
3340
3328
  input="|",
3341
3329
  ),
3342
- callback=self.glue_columns,
3330
+ callback=self.glue_list_column,
3343
3331
  )
3344
3332
 
3345
3333
  @with_full_df
3346
3334
  @with_busy_screen
3347
- def glue_columns(self, result: str | None) -> None:
3335
+ def glue_list_column(self, result: str | None) -> None:
3348
3336
  """Glue list items of the current column into a single string per row.
3349
3337
 
3350
3338
  Args:
@@ -3356,7 +3344,7 @@ class DataFrameTable(DataTable):
3356
3344
  delimiter = result # empty string is a valid delimiter
3357
3345
  cidx = self.cursor_cidx
3358
3346
  col_name = self.cursor_col_name
3359
- new_col_name = self._get_column_name(f"{col_name}_glued")
3347
+ new_col_name = self._new_column_name(f"{col_name}_glued")
3360
3348
 
3361
3349
  self.add_history(
3362
3350
  f"Glue list column [$success]{col_name}[/] into [$success]{new_col_name}[/] with delimiter [$accent]{delimiter}[/]",
@@ -3393,6 +3381,7 @@ class DataFrameTable(DataTable):
3393
3381
  self.log(f"Error gluing list column `{col_name}`: {e}")
3394
3382
 
3395
3383
  @with_full_df
3384
+ @with_busy_screen
3396
3385
  def cmd_expand_list_column(self) -> None:
3397
3386
  """Expand the current list column into multiple indexed columns.
3398
3387
 
@@ -3468,6 +3457,7 @@ class DataFrameTable(DataTable):
3468
3457
  self.log(f"Error expanding list column `{col_name}`: {e}")
3469
3458
 
3470
3459
  @with_full_df
3460
+ @with_busy_screen
3471
3461
  def cmd_contract_list_column(self) -> None:
3472
3462
  """Contract indexed sibling columns back into a single list column.
3473
3463
 
@@ -3642,6 +3632,7 @@ class DataFrameTable(DataTable):
3642
3632
  self.log(f"Error adding link column: {e}")
3643
3633
 
3644
3634
  @with_full_df
3635
+ @with_busy_screen
3645
3636
  def cmd_delete_column(self, more: str | None = None, col_name: str | None = None) -> None:
3646
3637
  """Remove selected columns when present, otherwise the current column.
3647
3638
 
@@ -3866,6 +3857,7 @@ class DataFrameTable(DataTable):
3866
3857
  self.log(f"Error exploding column `{col_name}` `{delimiter}`: {e}")
3867
3858
 
3868
3859
  @with_full_df
3860
+ @with_busy_screen
3869
3861
  def cmd_delete_row(self, more: str | None = None) -> None:
3870
3862
  """Delete rows from the table and dataframe.
3871
3863
 
@@ -3936,6 +3928,7 @@ class DataFrameTable(DataTable):
3936
3928
  self.notify(f"Deleted [$success]{deleted_count}[/] row(s)", title="Delete Row(s)")
3937
3929
 
3938
3930
  @with_full_df
3931
+ @with_busy_screen
3939
3932
  def cmd_duplicate_row(self) -> None:
3940
3933
  """Duplicate the currently selected row, inserting it right after the current row."""
3941
3934
  ridx = self.cursor_ridx
@@ -3972,6 +3965,7 @@ class DataFrameTable(DataTable):
3972
3965
  self.notify(f"Duplicated row [$success]{ridx + 1}[/]", title="Duplicate Row")
3973
3966
 
3974
3967
  @with_full_df
3968
+ @with_busy_screen
3975
3969
  def cmd_duplicate_column(self) -> None:
3976
3970
  """Duplicate the currently selected column, inserting it right after the current column."""
3977
3971
  cidx = self.cursor_cidx
@@ -4012,6 +4006,7 @@ class DataFrameTable(DataTable):
4012
4006
  )
4013
4007
 
4014
4008
  @with_full_df
4009
+ @with_busy_screen
4015
4010
  def cmd_remove_duplicates(self) -> None:
4016
4011
  """Remove duplicate rows from the current dataframe, keeping the first occurrence."""
4017
4012
  subset = list(self.visible_columns.keys())
@@ -4274,6 +4269,8 @@ class DataFrameTable(DataTable):
4274
4269
 
4275
4270
  self.notify(f"Moved row [$success]{curr_key.value}[/] {direction}", title="Move Row")
4276
4271
 
4272
+ @with_full_df
4273
+ @with_busy_screen
4277
4274
  def cmd_transpose(self) -> None:
4278
4275
  """Transpose the dataframe, swapping rows and columns."""
4279
4276
  if not self.visible_columns:
@@ -4700,16 +4697,7 @@ class DataFrameTable(DataTable):
4700
4697
 
4701
4698
  return matches
4702
4699
 
4703
- def cmd_find_forward(self, forward: bool = True, scope: str = "column") -> None:
4704
- """Open expression search prefilled with cursor value.
4705
-
4706
- Args:
4707
- forward: Whether to navigate forward.
4708
- scope: "column" or "all" (global).
4709
- """
4710
- self.cmd_find_backward(forward=forward, scope=scope)
4711
-
4712
- def _find_cursor_direct(self, forward: bool = True, scope: str = "column") -> None:
4700
+ def _find_cursor(self, forward: bool = True, scope: str = "column") -> None:
4713
4701
  """Search immediately using the cursor value without opening SearchScreen.
4714
4702
 
4715
4703
  Args:
@@ -4734,20 +4722,30 @@ class DataFrameTable(DataTable):
4734
4722
 
4735
4723
  def cmd_find_cursor_all(self) -> None:
4736
4724
  """Search the entire dataframe for the current cursor value, highlight all matches, and go to the first."""
4737
- self._find_cursor_direct(forward=True, scope="global")
4725
+ self._find_cursor(forward=True, scope="global")
4738
4726
 
4739
4727
  # Move to the very first match in the dataframe
4740
4728
  if self.matches and self.ordered_matches:
4741
4729
  first_ridx, first_cidx = self.ordered_matches[0]
4742
4730
  self.move_cursor_to(first_ridx, first_cidx)
4743
4731
 
4744
- def cmd_find_backward(self, forward: bool = False, scope: str = "column") -> None:
4732
+ def cmd_find_forward(self, scope: str = "column") -> None:
4733
+ """Open expression search prefilled with cursor value.
4734
+
4735
+ Args:
4736
+ scope: "column" or "all" (global).
4737
+ """
4738
+ self._find_value(forward=True, scope=scope)
4739
+
4740
+ def cmd_find_backward(self, scope: str = "column") -> None:
4745
4741
  """Open expression search screen.
4746
4742
 
4747
4743
  Args:
4748
- forward: Whether to navigate to the next match after applying results.
4749
4744
  scope: "column" or "all" (global).
4750
4745
  """
4746
+ self._find_value(forward=False, scope=scope)
4747
+
4748
+ def _find_value(self, forward: bool = True, scope: str = "column") -> None:
4751
4749
  # Use current cell value as default search term
4752
4750
  term = NULL if self.cursor_value is None else str(self.cursor_value)
4753
4751
  col_name = self.cursor_col_name
@@ -4762,7 +4760,6 @@ class DataFrameTable(DataTable):
4762
4760
  callback=partial(self.find, scope=scope, forward=forward),
4763
4761
  )
4764
4762
 
4765
- @with_full_df
4766
4763
  def find(self, result: dict, scope: str = "column", forward: bool = True) -> None:
4767
4764
  """Find a term in current column or globally across all columns.
4768
4765
 
@@ -4817,8 +4814,8 @@ class DataFrameTable(DataTable):
4817
4814
  match_count = sum(len(cols) for cols in matches.values())
4818
4815
  self.matches = matches
4819
4816
 
4820
- message = f"Found [$success]{match_count}[/] matches for `[$accent]{term}[/]`"
4821
- message += f" in [$accent]{col_name}[/]" if scope == "column" else " across all columns"
4817
+ message = f"Found [$success]{match_count}[/] matches for [$accent]{term}[/] in "
4818
+ message += f"column [$success]{col_name}[/]" if scope == "column" else "[$success]all columns[/]"
4822
4819
  self.notify(message, title=title)
4823
4820
 
4824
4821
  # Recreate table for display
@@ -6002,6 +5999,7 @@ class DataFrameTable(DataTable):
6002
5999
 
6003
6000
  self.update_cell(row_key, col_key, cell_text)
6004
6001
 
6002
+ @with_full_df
6005
6003
  def cmd_select_row_above(self) -> None:
6006
6004
  """Select current row and all rows above it."""
6007
6005
  ridx = self.cursor_ridx
@@ -6011,6 +6009,7 @@ class DataFrameTable(DataTable):
6011
6009
  self.setup_table()
6012
6010
  self.notify(f"Selected [$success]{len(rids)}[/] row(s) (current + above)", title="Select Rows")
6013
6011
 
6012
+ @with_full_df
6014
6013
  def cmd_select_row_below(self) -> None:
6015
6014
  """Select current row and all rows below it."""
6016
6015
  ridx = self.cursor_ridx
@@ -6132,7 +6131,6 @@ class DataFrameTable(DataTable):
6132
6131
  self.notify("Failed to copy to clipboard", title="Copy to Clipboard", severity="error")
6133
6132
 
6134
6133
  # SQL Interface
6135
- @with_full_df
6136
6134
  def cmd_sql_simple(self) -> None:
6137
6135
  """Open the SQL interface screen."""
6138
6136
  self.app.push_screen(
@@ -6152,7 +6150,6 @@ class DataFrameTable(DataTable):
6152
6150
 
6153
6151
  self.run_sql(sql, new_tab)
6154
6152
 
6155
- @with_full_df
6156
6153
  def cmd_sql_advanced(self) -> None:
6157
6154
  """Open the advanced SQL interface screen."""
6158
6155
  self.app.push_screen(
@@ -6160,6 +6157,64 @@ class DataFrameTable(DataTable):
6160
6157
  callback=self.advanced_sql,
6161
6158
  )
6162
6159
 
6160
+ def advanced_sql(self, result) -> None:
6161
+ """Handle SQL result result from AdvancedSqlScreen."""
6162
+ if result is None:
6163
+ return
6164
+ sql, new_tab = result
6165
+
6166
+ self.run_sql(sql, new_tab)
6167
+
6168
+ @with_full_df
6169
+ def run_sql(self, sql: str, new_tab: bool = False) -> None:
6170
+ """Execute a SQL query directly.
6171
+
6172
+ Args:
6173
+ sql: The SQL query string to execute.
6174
+ new_tab: Whether to show results in a new tab or update the current view.
6175
+ """
6176
+ # handle special internal row identifier column references
6177
+ sql = sql.replace("RID", RID).replace("$#", f"(`{RID}` + 1)")
6178
+
6179
+ # Execute the SQL query
6180
+ try:
6181
+ df_filtered = add_rid_column(self.df.lazy().sql(sql)).collect()
6182
+ if len(df_filtered) == 0:
6183
+ self.notify(f"Query returned no results for [$warning]{sql}[/]", title="SQL Query", severity="warning")
6184
+ return
6185
+
6186
+ except Exception as e:
6187
+ self.notify(f"Failed to execute SQL query [$error]{sql}[/]", title="SQL Query", severity="error")
6188
+ self.log(f"Error executing SQL query `{sql}`: {e}")
6189
+ return
6190
+
6191
+ # Show results in new tab if requested
6192
+ if new_tab:
6193
+ return self.app.add_tab(
6194
+ df_filtered,
6195
+ filename="query_results.csv",
6196
+ tabname="query-results",
6197
+ after=self.app.tabbed.active_pane,
6198
+ )
6199
+
6200
+ # Add to history
6201
+ self.add_history(f"Run SQL Query: [$success]{sql}[/]")
6202
+
6203
+ # Store original dataframe in dfull if not already in a view
6204
+ if not self.in_view:
6205
+ self.dfull = self.df
6206
+
6207
+ # Update dataframe
6208
+ self.df = df_filtered
6209
+
6210
+ # Recreate table for display
6211
+ self.setup_table()
6212
+
6213
+ self.notify(
6214
+ f"Query executed successfully. Now showing [$accent]{len(self.df)}[/] rows and [$accent]{len(self.df.columns)}[/] columns.",
6215
+ title="SQL Query",
6216
+ )
6217
+
6163
6218
  def cmd_toggle_python_console(self) -> None:
6164
6219
  """Toggle the embedded Python console for the current tab."""
6165
6220
  console = self.app.console_panel
@@ -6233,61 +6288,3 @@ class DataFrameTable(DataTable):
6233
6288
  self.notify(f"Error calling {cmd_name}: {e}", title="Run Command", severity="error")
6234
6289
  except Exception as e:
6235
6290
  self.notify(f"{cmd_name} failed: {e}", title="Run Command", severity="error")
6236
-
6237
- def advanced_sql(self, result) -> None:
6238
- """Handle SQL result result from AdvancedSqlScreen."""
6239
- if result is None:
6240
- return
6241
- sql, new_tab = result
6242
-
6243
- self.run_sql(sql, new_tab)
6244
-
6245
- @with_full_df
6246
- def run_sql(self, sql: str, new_tab: bool = False) -> None:
6247
- """Execute a SQL query directly.
6248
-
6249
- Args:
6250
- sql: The SQL query string to execute.
6251
- new_tab: Whether to show results in a new tab or update the current view.
6252
- """
6253
- # handle special internal row identifier column references
6254
- sql = sql.replace("RID", RID).replace("$#", f"(`{RID}` + 1)")
6255
-
6256
- # Execute the SQL query
6257
- try:
6258
- df_filtered = add_rid_column(self.df.lazy().sql(sql)).collect()
6259
- if len(df_filtered) == 0:
6260
- self.notify(f"Query returned no results for [$warning]{sql}[/]", title="SQL Query", severity="warning")
6261
- return
6262
-
6263
- except Exception as e:
6264
- self.notify(f"Failed to execute SQL query [$error]{sql}[/]", title="SQL Query", severity="error")
6265
- self.log(f"Error executing SQL query `{sql}`: {e}")
6266
- return
6267
-
6268
- # Show results in new tab if requested
6269
- if new_tab:
6270
- return self.app.add_tab(
6271
- df_filtered,
6272
- filename="query_results.csv",
6273
- tabname="query-results",
6274
- after=self.app.tabbed.active_pane,
6275
- )
6276
-
6277
- # Add to history
6278
- self.add_history(f"Run SQL Query: [$success]{sql}[/]")
6279
-
6280
- # Store original dataframe in dfull if not already in a view
6281
- if not self.in_view:
6282
- self.dfull = self.df
6283
-
6284
- # Update dataframe
6285
- self.df = df_filtered
6286
-
6287
- # Recreate table for display
6288
- self.setup_table()
6289
-
6290
- self.notify(
6291
- f"Query executed successfully. Now showing [$accent]{len(self.df)}[/] rows and [$accent]{len(self.df.columns)}[/] columns.",
6292
- title="SQL Query",
6293
- )
@@ -433,6 +433,11 @@ class TableScreen(TableModalScreen):
433
433
  self.notify(f"Column [$warning]{col_name}[/] not found", title="Filter Value", severity="warning")
434
434
  return
435
435
 
436
+ # Dismiss modal screen(s) to return to main table first: filtering/collecting
437
+ # pushes a transient BusyScreen, so popping afterward would remove that instead.
438
+ while len(self.app._screen_stack) > 1:
439
+ self.app.pop_screen()
440
+
436
441
  # Action collect
437
442
  if action == "collect":
438
443
  self.dftable.cmd_collect_rows(col_name=col_name, term=values)
@@ -450,11 +455,6 @@ class TableScreen(TableModalScreen):
450
455
  }
451
456
  )
452
457
 
453
- # Dismiss modal screen(s) to return to main table
454
- while len(self.app._screen_stack) > 1:
455
- self.app.pop_screen()
456
- break
457
-
458
458
  self.dftable.move_cursor(column=cidx)
459
459
 
460
460
  def show_frequency(self, *col_names: str) -> None:
@@ -1080,6 +1080,11 @@ class FrequencyScreen(TableScreen):
1080
1080
  self.notify(f"Column [$warning]{col_name}[/] not found", title="Frequency", severity="warning")
1081
1081
  return
1082
1082
 
1083
+ # Dismiss modal screen(s) to return to main table first: filtering/collecting
1084
+ # pushes a transient BusyScreen, so popping afterward would remove that instead.
1085
+ while len(self.app._screen_stack) > 1:
1086
+ self.app.pop_screen()
1087
+
1083
1088
  if action == "collect":
1084
1089
  self.dftable.cmd_collect_rows(col_name=col_name, term=expr)
1085
1090
  else:
@@ -1094,11 +1099,6 @@ class FrequencyScreen(TableScreen):
1094
1099
  }
1095
1100
  )
1096
1101
 
1097
- # Dismiss modal screen to return to main table.
1098
- while len(self.app._screen_stack) > 1:
1099
- self.app.pop_screen()
1100
- break
1101
-
1102
1102
  self.dftable.move_cursor(column=cidx)
1103
1103
 
1104
1104
 
@@ -13,6 +13,7 @@ from textual.app import ComposeResult
13
13
  from textual.containers import Container, Horizontal, Vertical
14
14
  from textual.events import Key
15
15
  from textual.screen import ModalScreen
16
+ from textual.validation import ValidationResult, Validator
16
17
  from textual.widgets import (
17
18
  Button,
18
19
  Checkbox,
@@ -33,6 +34,16 @@ from .common import NULL, RID, DtypeClass, DtypeConfig, tentative_expr, validate
33
34
  from .keybindings import KeyBinding, format_key_display, parse_key_display
34
35
 
35
36
 
37
+ class NonEmptyValueValidator(Validator):
38
+ """Validator that rejects empty or whitespace-only input values."""
39
+
40
+ def validate(self, value: str) -> ValidationResult:
41
+ """Return success when input contains non-whitespace characters."""
42
+ if value.strip():
43
+ return self.success()
44
+ return self.failure("Value cannot be empty")
45
+
46
+
36
47
  class YMNScreen(ModalScreen):
37
48
  """Base class for Yes/Maybe/No modal screens with customizable content and callbacks.
38
49
 
@@ -716,7 +727,7 @@ class RenameColumnScreen(YesNoScreen):
716
727
  super().__init__(
717
728
  title="Rename Column",
718
729
  label=content,
719
- input={"value": col_name},
730
+ input=Input(col_name, validators=NonEmptyValueValidator()),
720
731
  yes="Rename",
721
732
  no="Cancel",
722
733
  on_yes_callback=self._validate_input,
@@ -789,7 +800,7 @@ class AddColumnScreen(YesNoScreen):
789
800
  label="Column name",
790
801
  input="Link" if link else "New column",
791
802
  label2=label2,
792
- input2="Link template" if link else "Value or Polars expression",
803
+ input2=Input(placeholder="Link template" if link else "Value or Polars expression"),
793
804
  yes="Add",
794
805
  no="Cancel",
795
806
  on_yes_callback=self._get_input,
@@ -187,7 +187,7 @@ wheels = [
187
187
 
188
188
  [[package]]
189
189
  name = "dataframe-textual"
190
- version = "3.1.1"
190
+ version = "3.1.3"
191
191
  source = { editable = "." }
192
192
  dependencies = [
193
193
  { name = "fastexcel" },