dataframe-textual 3.1.0__tar.gz → 3.1.2__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.0 → dataframe_textual-3.1.2}/PKG-INFO +2 -2
  2. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/pyproject.toml +1 -1
  3. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/common.py +6 -6
  4. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/data_frame_table.py +279 -241
  5. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/table_screen.py +10 -10
  6. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/yes_no_screen.py +13 -2
  7. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/uv.lock +1 -1
  8. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/.gitignore +0 -0
  9. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/LICENSE +0 -0
  10. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/README.md +0 -0
  11. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/main.py +0 -0
  12. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/__init__.py +0 -0
  13. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/__main__.py +0 -0
  14. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/commands.py +0 -0
  15. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/console_panel.py +0 -0
  16. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/data_frame_viewer.py +0 -0
  17. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/file_picker_screen.py +0 -0
  18. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/help_panel.py +0 -0
  19. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/keybindings.py +0 -0
  20. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/loading_screen.py +0 -0
  21. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/run_command_screen.py +0 -0
  22. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/status_bar.py +0 -0
  23. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/src/dataframe_textual/text_screen.py +0 -0
  24. {dataframe_textual-3.1.0 → dataframe_textual-3.1.2}/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.0
3
+ Version: 3.1.2
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.0"
7
+ version = "3.1.2"
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.
@@ -1319,50 +1354,85 @@ class DataFrameTable(DataTable):
1319
1354
  # self.app._set_status_context(self)
1320
1355
 
1321
1356
  def determine_column_widths(self) -> dict[str, int]:
1322
- """Determine optimal width for each column based on data type and content.
1323
-
1324
- For String columns:
1325
- - Minimum width: length of column label
1326
- - Ideal width: maximum width of all cells in the column
1327
- - If space constrained: find appropriate width smaller than maximum
1328
-
1329
- For non-String columns:
1330
- - Return None to let Textual auto-determine width
1357
+ """Determine optimal width for each visible column based on data type and sampled content.
1358
+
1359
+ Algorithm (two phases):
1360
+
1361
+ **Phase 1 - initial widths:**
1362
+ - The column label width is always the floor (label is never clipped).
1363
+ - Bar columns are fixed to BAR_COLUMN_WIDTH.
1364
+ - User-overridden columns (positive width) are fixed to ``max(label, override)``.
1365
+ - URL-only string columns are skipped (let Textual auto-size so they stay clickable).
1366
+ - String columns whose sampled max exceeds COLUMN_WIDTH_CAP are capped at
1367
+ ``max(label_width, COLUMN_WIDTH_CAP)`` and queued for phase 2.
1368
+ - All other columns (numeric, bool, temporal, short strings, expanded columns)
1369
+ use their natural sampled max width.
1370
+
1371
+ **Phase 2 - expand capped columns with leftover space:**
1372
+ - Columns are processed in visible order.
1373
+ - If a column's ideal width fits in the remaining available space, expand it
1374
+ exactly to that width and move on.
1375
+ - If a column needs more than the remaining available space (it is "too wide"),
1376
+ distribute the remaining available space **evenly** among it and all
1377
+ subsequent capped columns, then stop.
1331
1378
 
1332
1379
  Returns:
1333
- dict[str, int]: Mapping of column name to width (None for auto-sizing columns).
1380
+ dict[str, int]: Mapping of column name to display width.
1334
1381
  """
1335
- col_widths, col_label_widths = {}, {}
1382
+ col_widths: dict[str, int] = {}
1383
+ col_label_widths: dict[str, int] = {}
1384
+ col_ideal_widths: dict[str, int] = {} # uncapped natural max from sampled data
1385
+ capped_cols: list[str] = [] # string cols capped in phase 1, in visible order
1336
1386
 
1387
+ # Pre-set bar columns
1337
1388
  for col in self.bar_columns:
1338
1389
  col_widths[col] = BAR_COLUMN_WIDTH
1339
1390
 
1340
- # Get available width for the table (with some padding for borders/scrollbar)
1391
+ # Available terminal width
1341
1392
  init_available_width = self.scrollable_content_region.width or self.app.size.width
1342
- available_width = init_available_width
1343
1393
 
1344
- # Sample a reasonable number of rows to calculate widths (don't scan entire dataframe)
1394
+ # Sample rows for width estimation
1345
1395
  sample_size = min(self.BATCH_SIZE, len(self.df))
1346
1396
  sample_lf = self.df.lazy().head(sample_size)
1347
1397
 
1348
- # Determine widths for each visible column
1349
- for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
1350
- # Get column label width
1351
- label_text = self._build_column_label(col, col_idx)
1352
- label_width = measure(self.app.console, label_text, 1) + 2
1398
+ # ── Phase 1: initial width for every visible column ───────────────────
1399
+ for col, dtype in self.visible_columns.items():
1400
+ # Label width is the hard minimum
1401
+ label_width = self._column_label_width(col)
1353
1402
  col_label_widths[col] = label_width
1354
1403
 
1355
- if label_width > col_widths.get(col, 0):
1356
- col_widths[col] = label_width
1404
+ # Bar columns: already fixed
1405
+ if col in self.bar_columns:
1406
+ col_ideal_widths[col] = col_widths[col]
1407
+ continue
1408
+
1409
+ # User-set fixed width: respect it
1410
+ if col in self.column_widths:
1411
+ override = self.column_widths[col]
1412
+ if override > 0:
1413
+ col_widths[col] = max(label_width, override)
1414
+ col_ideal_widths[col] = col_widths[col]
1415
+ continue
1416
+ # override == -1 means "expanded": fall through and skip the cap below
1417
+ # override == 0 means hidden: excluded from visible_columns already
1418
+
1419
+ dc = DtypeConfig(dtype)
1420
+ is_string = dc.gtype == "string"
1421
+ is_expanded = self.column_widths.get(col) == -1
1357
1422
 
1358
1423
  try:
1359
- # Get sample values from the column
1360
1424
  sample_values = sample_lf.select(col).collect().get_column(col).drop_nulls().to_list()
1361
- if dtype == pl.String and any(val.startswith(("https://", "http://")) for val in sample_values):
1362
- continue # Skip link columns so they can auto-size and be clickable
1363
1425
 
1364
- # Find maximum width in sample
1365
- # For list columns, measure the string representation of the first three items to avoid extremely long widths
1426
+ # URL columns: leave for Textual auto-sizing so links stay clickable
1427
+ if (
1428
+ is_string
1429
+ and sample_values
1430
+ and any(val.startswith(("https://", "http://")) for val in sample_values)
1431
+ ):
1432
+ col_widths[col] = label_width
1433
+ col_ideal_widths[col] = label_width
1434
+ continue
1435
+
1366
1436
  max_cell_width = max(
1367
1437
  (
1368
1438
  measure(self.app.console, str(val[:3]) if isinstance(val, list) else str(val), 1)
@@ -1370,46 +1440,50 @@ class DataFrameTable(DataTable):
1370
1440
  ),
1371
1441
  default=label_width,
1372
1442
  )
1373
-
1374
- # Set column width to max of label and sampled data (capped at reasonable max)
1375
- max_width = max(label_width, max_cell_width)
1376
1443
  except Exception as e:
1377
- # If any error, let Textual auto-size
1378
- max_width = label_width
1379
1444
  self.log(f"Error determining width for column `{col}`: {e}")
1445
+ max_cell_width = label_width
1380
1446
 
1381
- col_widths[col] = max_width
1382
- available_width -= max_width
1383
-
1384
- for col, width in self.column_widths.items():
1385
- if width > 0 and col in col_widths:
1386
- old_width = col_widths[col]
1387
- col_widths[col] = max(col_label_widths[col], width)
1388
- available_width -= col_widths[col] - old_width
1389
-
1390
- # If there's no more available width, auto-size remaining columns
1391
- if available_width < 0:
1392
- # Recalculate available width after capping wide columns
1393
- available_width = init_available_width
1394
- for col in col_widths:
1395
- if col in self.column_widths and self.column_widths[col] != 0:
1396
- available_width -= col_widths[col]
1397
- continue
1398
- if col_widths[col] > COLUMN_WIDTH_CAP and col_label_widths[col] < COLUMN_WIDTH_CAP:
1399
- col_widths[col] = COLUMN_WIDTH_CAP # Cap width to prevent extremely wide columns
1400
- available_width -= col_widths[col]
1401
-
1402
- # If there's still available width, distribute it proportionally to columns that are above the cap
1403
- if available_width > BUFFER_SIZE:
1404
- flexible_cols = [
1405
- col for col in col_widths if col not in self.column_widths and col_widths[col] >= COLUMN_WIDTH_CAP
1447
+ ideal_width = max(label_width, max_cell_width)
1448
+ col_ideal_widths[col] = ideal_width
1449
+
1450
+ if is_string and not is_expanded and ideal_width > COLUMN_WIDTH_CAP:
1451
+ # Cap and queue for phase 2
1452
+ col_widths[col] = max(label_width, COLUMN_WIDTH_CAP)
1453
+ capped_cols.append(col)
1454
+ else:
1455
+ # Numeric / bool / temporal / short string / expanded: natural width
1456
+ col_widths[col] = ideal_width
1457
+
1458
+ # ── Phase 2: expand capped columns sequentially with leftover space ──
1459
+ available_width = init_available_width - sum(col_widths.values())
1460
+
1461
+ if available_width > 0 and capped_cols:
1462
+ # Only columns that can still grow
1463
+ expandable = [
1464
+ (col, col_ideal_widths[col] - col_widths[col])
1465
+ for col in capped_cols
1466
+ if col_ideal_widths.get(col, 0) > col_widths.get(col, 0)
1406
1467
  ]
1407
- # Only distribute if there's more than one flexible column to avoid giving all extra space to a single column
1408
- if len(flexible_cols) > 1:
1409
- extra_width_per_col = (available_width - BUFFER_SIZE) // len(flexible_cols)
1410
- for col in flexible_cols:
1411
- new_width = col_widths[col] + extra_width_per_col
1412
- col_widths[col] = max(new_width, COLUMN_WIDTH_CAP)
1468
+
1469
+ i = 0
1470
+ while i < len(expandable) and available_width > 0:
1471
+ col, needed = expandable[i]
1472
+
1473
+ if needed <= available_width:
1474
+ # Enough room: give the column exactly what it needs
1475
+ col_widths[col] += needed
1476
+ available_width -= needed
1477
+ i += 1
1478
+ else:
1479
+ # Column is too wide for remaining space: distribute
1480
+ # available_width evenly among this and all remaining capped columns
1481
+ remaining = expandable[i:]
1482
+ share = available_width // len(remaining)
1483
+ for rcol, _ in remaining:
1484
+ col_widths[rcol] += share
1485
+ available_width = 0
1486
+ break
1413
1487
 
1414
1488
  return col_widths
1415
1489
 
@@ -1426,38 +1500,12 @@ class DataFrameTable(DataTable):
1426
1500
 
1427
1501
  # Add columns with justified headers
1428
1502
  for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
1429
- cell_value = self._build_column_label(col, col_idx)
1503
+ label = self._build_column_label(col, col_idx)
1430
1504
 
1431
1505
  # Get the width for this column (None means auto-size)
1432
1506
  width = column_widths.get(col)
1433
1507
 
1434
- self.add_column(Text(cell_value, justify=DtypeConfig(dtype).justify), key=col, width=width)
1435
-
1436
- def _build_column_label(self, col_name: str, visible_col_idx: int | None = None) -> str:
1437
- """Build display label for a column header.
1438
-
1439
- Args:
1440
- col_name: Source dataframe column name.
1441
- visible_col_idx: 1-based index of the column among visible columns.
1442
-
1443
- Returns:
1444
- Column label text with optional index prefix and sort indicator.
1445
- """
1446
- label = col_name
1447
- if self.show_column_index:
1448
- label = f"{visible_col_idx or self.cursor_column + 1}_{label}"
1449
-
1450
- for idx, c in enumerate(self.sorted_columns, 1):
1451
- if c == col_name:
1452
- # Add sort indicator to column header
1453
- descending = self.sorted_columns[col_name]
1454
- sort_indicator = (
1455
- f" ▼{SUBSCRIPT_DIGITS.get(idx, '')}" if descending else f" ▲{SUBSCRIPT_DIGITS.get(idx, '')}"
1456
- )
1457
- label = col_name + sort_indicator
1458
- break
1459
-
1460
- return label
1508
+ self.add_column(Text(label, justify=DtypeConfig(dtype).justify), key=col, width=width)
1461
1509
 
1462
1510
  def _calculate_load_range(self, start: int, stop: int) -> list[tuple[int, int]]:
1463
1511
  """Calculate the actual ranges to load, accounting for already-loaded ranges.
@@ -1639,7 +1687,7 @@ class DataFrameTable(DataTable):
1639
1687
  # Load the dataframe slice
1640
1688
  df_slice = self.df.slice(segment_start, segment_stop - segment_start)
1641
1689
  thousand_separator = [col in self.thousand_separator_columns for col in visible_columns]
1642
- 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]
1643
1691
 
1644
1692
  # Load each row at the correct position
1645
1693
  for (ridx, row), rid in zip(enumerate(df_slice.iter_rows(), segment_start), df_slice[RID]):
@@ -2215,6 +2263,8 @@ class DataFrameTable(DataTable):
2215
2263
  )
2216
2264
  return
2217
2265
 
2266
+ self.add_history(f"Toggle bar chart for column [$accent]{col_name}[/]", dirty=False)
2267
+
2218
2268
  # Toggle bar display
2219
2269
  if col_name in self.bar_columns:
2220
2270
  self.bar_columns.discard(col_name)
@@ -2252,7 +2302,9 @@ class DataFrameTable(DataTable):
2252
2302
  def cmd_toggle_freeze(self) -> None:
2253
2303
  """Toggle the freeze."""
2254
2304
  if self.fixed_rows or self.fixed_columns:
2305
+ self.add_history("Unfreeze all rows and columns")
2255
2306
  self.fixed_rows = self.fixed_columns = 0
2307
+ self.setup_table()
2256
2308
  self.notify("Unfreezed all rows and columns", title="Freeze Row/Column")
2257
2309
  else:
2258
2310
  self.app.push_screen(FreezeScreen(), callback=self.toggle_freeze_row_column)
@@ -2347,11 +2399,11 @@ class DataFrameTable(DataTable):
2347
2399
  return None
2348
2400
  col: Column = self.columns[col_key]
2349
2401
 
2350
- label_width = len(self._build_column_label(col_name)) + 2
2402
+ label_width = self._column_label_width(col_name)
2351
2403
 
2352
2404
  # If already expanded, shrink back
2353
- if col_name in self.expanded_columns:
2354
- col.width = max(label_width, COLUMN_WIDTH_CAP)
2405
+ if self.column_widths.get(col_name) == -1:
2406
+ col.width = label_width
2355
2407
  self.column_widths.pop(col_name, None)
2356
2408
  return f"[$success]{col_name}[/] shrunk to [$accent]{col.width}[/]"
2357
2409
 
@@ -2362,7 +2414,17 @@ class DataFrameTable(DataTable):
2362
2414
 
2363
2415
  for row_start, row_end in self.loaded_ranges:
2364
2416
  for ridx in range(row_start, row_end):
2365
- 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
+
2366
2428
  cell_width = measure(self.app.console, cell_value, 1)
2367
2429
  if cell_width > new_width:
2368
2430
  need_expand = True
@@ -2371,7 +2433,7 @@ class DataFrameTable(DataTable):
2371
2433
  if not need_expand:
2372
2434
  return None
2373
2435
 
2374
- self.column_widths[col_name] = -1
2436
+ self.column_widths[col_name] = -1 # Mark as expanded
2375
2437
  col.width = new_width
2376
2438
  return f"[$success]{col_name}[/] expanded to [$accent]{new_width}[/]"
2377
2439
 
@@ -2397,8 +2459,7 @@ class DataFrameTable(DataTable):
2397
2459
 
2398
2460
  results = []
2399
2461
  for col_name in target_cols:
2400
- result = self._expand_single_column(col_name)
2401
- if result:
2462
+ if result := self._expand_single_column(col_name):
2402
2463
  results.append(result)
2403
2464
 
2404
2465
  if not results:
@@ -2418,8 +2479,8 @@ class DataFrameTable(DataTable):
2418
2479
  return
2419
2480
 
2420
2481
  col_name = self.cursor_col_key.value
2421
- result = self._expand_single_column(col_name)
2422
- if not result:
2482
+
2483
+ if not (result := self._expand_single_column(col_name)):
2423
2484
  return
2424
2485
 
2425
2486
  self._update_count += 1
@@ -2676,7 +2737,7 @@ class DataFrameTable(DataTable):
2676
2737
 
2677
2738
  # Expand column width if new content is wider than the explicit width set during setup
2678
2739
  col = self.columns[col_key]
2679
- new_content_width = measure(self.app.console, str(display_value), 1) + 2
2740
+ new_content_width = measure(self.app.console, str(display_value), 1)
2680
2741
  if col.width is not None and new_content_width > col.width:
2681
2742
  col.width = new_content_width
2682
2743
 
@@ -2815,12 +2876,6 @@ class DataFrameTable(DataTable):
2815
2876
 
2816
2877
  col_name, new_name = result
2817
2878
  col_idx = self.get_col_idx(col_name)
2818
- if new_name is None:
2819
- self.app.push_screen(
2820
- RenameColumnScreen(col_name, self.df.columns),
2821
- callback=self.rename_column,
2822
- )
2823
- return
2824
2879
 
2825
2880
  # Add to history
2826
2881
  self.add_history(f"Rename column [$success]{col_name}[/] to [$accent]{new_name}[/]", dirty=True)
@@ -2859,6 +2914,8 @@ class DataFrameTable(DataTable):
2859
2914
 
2860
2915
  self.notify(f"Renamed column [$success]{col_name}[/] to [$accent]{new_name}[/]", title="Rename Column")
2861
2916
 
2917
+ @with_full_df
2918
+ @with_busy_screen
2862
2919
  def cmd_clear_cell(self) -> None:
2863
2920
  """Clear the current cell by setting its value to None."""
2864
2921
  row_key, col_key = self.cursor_key
@@ -2908,6 +2965,8 @@ class DataFrameTable(DataTable):
2908
2965
  )
2909
2966
  self.log(f"Error clearing cell ({ridx}, {col_name}): {e}")
2910
2967
 
2968
+ @with_full_df
2969
+ @with_busy_screen
2911
2970
  def cmd_clear_column(self) -> None:
2912
2971
  """Clear cells in the current column that match the cursor value by setting them to None."""
2913
2972
  col_idx = self.cursor_column
@@ -2945,7 +3004,7 @@ class DataFrameTable(DataTable):
2945
3004
  self.notify(f"Failed to clear column [$error]{col_name}[/]", title="Clear Column", severity="error")
2946
3005
  self.log(f"Error clearing column `{col_name}`: {e}")
2947
3006
 
2948
- def _get_column_name(self, col_name: str) -> str:
3007
+ def _new_column_name(self, col_name: str) -> str:
2949
3008
  """Get a unique column name based on the provided name."""
2950
3009
  if col_name not in self.df.columns:
2951
3010
  return col_name
@@ -2958,47 +3017,15 @@ class DataFrameTable(DataTable):
2958
3017
  new_col_name = f"{base_name}_{counter}"
2959
3018
  return new_col_name
2960
3019
 
2961
- @with_full_df
2962
3020
  def cmd_add_column(self, col_name: str | None = None) -> None:
2963
3021
  """Add acolumn after the current column."""
2964
- cidx = self.cursor_cidx
2965
-
2966
3022
  # Generate a unique column name
2967
3023
  if not col_name:
2968
- new_col_name = self._get_column_name("new_col")
3024
+ new_col_name = self._new_column_name("new_col")
2969
3025
  else:
2970
- new_col_name = col_name
2971
-
2972
- # Add to history
2973
- self.add_history(f"Add column [$success]{new_col_name}[/] after column [$accent]{cidx + 1}[/]", dirty=True)
2974
-
2975
- try:
2976
- # Create an empty column (all None values)
2977
- new_col = pl.lit(None).alias(new_col_name)
2978
-
2979
- # Get columns up to current, the new column, then remaining columns
2980
- cols = self.df.columns
2981
- cols_before = cols[: cidx + 1]
2982
- cols_after = cols[cidx + 1 :]
3026
+ new_col_name = self._new_column_name(col_name)
2983
3027
 
2984
- # Build the new dataframe with columns reordered
2985
- select_cols = cols_before + [new_col] + cols_after
2986
- self.df = self.df.lazy().with_columns(new_col).select(select_cols).collect()
2987
-
2988
- # Also update the full datafram if applicable
2989
- if self.in_view:
2990
- self.dfull = self.dfull.lazy().with_columns(new_col).select(select_cols).collect()
2991
-
2992
- # Recreate table for display
2993
- self.setup_table()
2994
-
2995
- # Move cursor to the new column
2996
- self.move_cursor(column=cidx + 1)
2997
-
2998
- self.notify(f"Added column [$success]{new_col_name}[/]", title="Add Column")
2999
- except Exception as e:
3000
- self.notify(f"Failed to add column [$error]{new_col_name}[/]", title="Add Column", severity="error")
3001
- 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)))
3002
3029
 
3003
3030
  def cmd_add_column_expr(self) -> None:
3004
3031
  """Open screen to add a new column with optional expression."""
@@ -3055,6 +3082,7 @@ class DataFrameTable(DataTable):
3055
3082
  self.log(f"Error adding column `{new_col_name}`: {e}")
3056
3083
 
3057
3084
  @with_full_df
3085
+ @with_busy_screen
3058
3086
  def cmd_add_index_column(self, start: int = 1, step: int = 1) -> None:
3059
3087
  """Add an index column after the current column.
3060
3088
 
@@ -3063,7 +3091,7 @@ class DataFrameTable(DataTable):
3063
3091
  step: Step between values in the sequence. Defaults to 1.
3064
3092
  """
3065
3093
  cidx = self.cursor_cidx
3066
- new_col_name = self._get_column_name("index")
3094
+ new_col_name = self._new_column_name("index")
3067
3095
 
3068
3096
  # Add to history
3069
3097
  self.add_history(
@@ -3147,7 +3175,7 @@ class DataFrameTable(DataTable):
3147
3175
 
3148
3176
  cidx = self.cursor_cidx
3149
3177
  col_name = self.cursor_col_name
3150
- new_col_name = self._get_column_name(f"{col_name}_split")
3178
+ new_col_name = self._new_column_name(f"{col_name}_split")
3151
3179
 
3152
3180
  self.add_history(
3153
3181
  f"Split column [$success]{col_name}[/] into [$success]{new_col_name}[/] using delimiter [$accent]{delimiter}[/]",
@@ -3236,7 +3264,7 @@ class DataFrameTable(DataTable):
3236
3264
 
3237
3265
  cidx = self.cursor_cidx
3238
3266
  base_name = "_".join(ordered_selected)
3239
- new_col_name = self._get_column_name(base_name)
3267
+ new_col_name = self._new_column_name(base_name)
3240
3268
 
3241
3269
  self.add_history(
3242
3270
  f"Join [$accent]{len(ordered_selected)}[/] columns into [$success]{new_col_name}[/] with delimiter [$accent]{delimiter}[/]",
@@ -3299,12 +3327,12 @@ class DataFrameTable(DataTable):
3299
3327
  label=f"Enter the delimiter to join items of [$success]{col_name}[/] into a string",
3300
3328
  input="|",
3301
3329
  ),
3302
- callback=self.glue_columns,
3330
+ callback=self.glue_list_column,
3303
3331
  )
3304
3332
 
3305
3333
  @with_full_df
3306
3334
  @with_busy_screen
3307
- def glue_columns(self, result: str | None) -> None:
3335
+ def glue_list_column(self, result: str | None) -> None:
3308
3336
  """Glue list items of the current column into a single string per row.
3309
3337
 
3310
3338
  Args:
@@ -3316,7 +3344,7 @@ class DataFrameTable(DataTable):
3316
3344
  delimiter = result # empty string is a valid delimiter
3317
3345
  cidx = self.cursor_cidx
3318
3346
  col_name = self.cursor_col_name
3319
- new_col_name = self._get_column_name(f"{col_name}_glued")
3347
+ new_col_name = self._new_column_name(f"{col_name}_glued")
3320
3348
 
3321
3349
  self.add_history(
3322
3350
  f"Glue list column [$success]{col_name}[/] into [$success]{new_col_name}[/] with delimiter [$accent]{delimiter}[/]",
@@ -3353,6 +3381,7 @@ class DataFrameTable(DataTable):
3353
3381
  self.log(f"Error gluing list column `{col_name}`: {e}")
3354
3382
 
3355
3383
  @with_full_df
3384
+ @with_busy_screen
3356
3385
  def cmd_expand_list_column(self) -> None:
3357
3386
  """Expand the current list column into multiple indexed columns.
3358
3387
 
@@ -3428,6 +3457,7 @@ class DataFrameTable(DataTable):
3428
3457
  self.log(f"Error expanding list column `{col_name}`: {e}")
3429
3458
 
3430
3459
  @with_full_df
3460
+ @with_busy_screen
3431
3461
  def cmd_contract_list_column(self) -> None:
3432
3462
  """Contract indexed sibling columns back into a single list column.
3433
3463
 
@@ -3602,6 +3632,7 @@ class DataFrameTable(DataTable):
3602
3632
  self.log(f"Error adding link column: {e}")
3603
3633
 
3604
3634
  @with_full_df
3635
+ @with_busy_screen
3605
3636
  def cmd_delete_column(self, more: str | None = None, col_name: str | None = None) -> None:
3606
3637
  """Remove selected columns when present, otherwise the current column.
3607
3638
 
@@ -3826,6 +3857,7 @@ class DataFrameTable(DataTable):
3826
3857
  self.log(f"Error exploding column `{col_name}` `{delimiter}`: {e}")
3827
3858
 
3828
3859
  @with_full_df
3860
+ @with_busy_screen
3829
3861
  def cmd_delete_row(self, more: str | None = None) -> None:
3830
3862
  """Delete rows from the table and dataframe.
3831
3863
 
@@ -3896,6 +3928,7 @@ class DataFrameTable(DataTable):
3896
3928
  self.notify(f"Deleted [$success]{deleted_count}[/] row(s)", title="Delete Row(s)")
3897
3929
 
3898
3930
  @with_full_df
3931
+ @with_busy_screen
3899
3932
  def cmd_duplicate_row(self) -> None:
3900
3933
  """Duplicate the currently selected row, inserting it right after the current row."""
3901
3934
  ridx = self.cursor_ridx
@@ -3932,6 +3965,7 @@ class DataFrameTable(DataTable):
3932
3965
  self.notify(f"Duplicated row [$success]{ridx + 1}[/]", title="Duplicate Row")
3933
3966
 
3934
3967
  @with_full_df
3968
+ @with_busy_screen
3935
3969
  def cmd_duplicate_column(self) -> None:
3936
3970
  """Duplicate the currently selected column, inserting it right after the current column."""
3937
3971
  cidx = self.cursor_cidx
@@ -3972,6 +4006,7 @@ class DataFrameTable(DataTable):
3972
4006
  )
3973
4007
 
3974
4008
  @with_full_df
4009
+ @with_busy_screen
3975
4010
  def cmd_remove_duplicates(self) -> None:
3976
4011
  """Remove duplicate rows from the current dataframe, keeping the first occurrence."""
3977
4012
  subset = list(self.visible_columns.keys())
@@ -4234,6 +4269,8 @@ class DataFrameTable(DataTable):
4234
4269
 
4235
4270
  self.notify(f"Moved row [$success]{curr_key.value}[/] {direction}", title="Move Row")
4236
4271
 
4272
+ @with_full_df
4273
+ @with_busy_screen
4237
4274
  def cmd_transpose(self) -> None:
4238
4275
  """Transpose the dataframe, swapping rows and columns."""
4239
4276
  if not self.visible_columns:
@@ -4660,16 +4697,7 @@ class DataFrameTable(DataTable):
4660
4697
 
4661
4698
  return matches
4662
4699
 
4663
- def cmd_find_forward(self, forward: bool = True, scope: str = "column") -> None:
4664
- """Open expression search prefilled with cursor value.
4665
-
4666
- Args:
4667
- forward: Whether to navigate forward.
4668
- scope: "column" or "all" (global).
4669
- """
4670
- self.cmd_find_backward(forward=forward, scope=scope)
4671
-
4672
- def _find_cursor_direct(self, forward: bool = True, scope: str = "column") -> None:
4700
+ def _find_cursor(self, forward: bool = True, scope: str = "column") -> None:
4673
4701
  """Search immediately using the cursor value without opening SearchScreen.
4674
4702
 
4675
4703
  Args:
@@ -4694,20 +4722,30 @@ class DataFrameTable(DataTable):
4694
4722
 
4695
4723
  def cmd_find_cursor_all(self) -> None:
4696
4724
  """Search the entire dataframe for the current cursor value, highlight all matches, and go to the first."""
4697
- self._find_cursor_direct(forward=True, scope="global")
4725
+ self._find_cursor(forward=True, scope="global")
4698
4726
 
4699
4727
  # Move to the very first match in the dataframe
4700
4728
  if self.matches and self.ordered_matches:
4701
4729
  first_ridx, first_cidx = self.ordered_matches[0]
4702
4730
  self.move_cursor_to(first_ridx, first_cidx)
4703
4731
 
4704
- 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:
4705
4741
  """Open expression search screen.
4706
4742
 
4707
4743
  Args:
4708
- forward: Whether to navigate to the next match after applying results.
4709
4744
  scope: "column" or "all" (global).
4710
4745
  """
4746
+ self._find_value(forward=False, scope=scope)
4747
+
4748
+ def _find_value(self, forward: bool = True, scope: str = "column") -> None:
4711
4749
  # Use current cell value as default search term
4712
4750
  term = NULL if self.cursor_value is None else str(self.cursor_value)
4713
4751
  col_name = self.cursor_col_name
@@ -4722,7 +4760,6 @@ class DataFrameTable(DataTable):
4722
4760
  callback=partial(self.find, scope=scope, forward=forward),
4723
4761
  )
4724
4762
 
4725
- @with_full_df
4726
4763
  def find(self, result: dict, scope: str = "column", forward: bool = True) -> None:
4727
4764
  """Find a term in current column or globally across all columns.
4728
4765
 
@@ -4777,8 +4814,8 @@ class DataFrameTable(DataTable):
4777
4814
  match_count = sum(len(cols) for cols in matches.values())
4778
4815
  self.matches = matches
4779
4816
 
4780
- message = f"Found [$success]{match_count}[/] matches for `[$accent]{term}[/]`"
4781
- 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[/]"
4782
4819
  self.notify(message, title=title)
4783
4820
 
4784
4821
  # Recreate table for display
@@ -5525,6 +5562,7 @@ class DataFrameTable(DataTable):
5525
5562
  )
5526
5563
 
5527
5564
  @with_full_df
5565
+ @with_busy_screen
5528
5566
  def cmd_collect_rows(self, col_name: str | None = None, term: Any | list[Any] = None) -> None:
5529
5567
  """Collect rows/columns to a new tab.
5530
5568
 
@@ -5962,6 +6000,7 @@ class DataFrameTable(DataTable):
5962
6000
 
5963
6001
  self.update_cell(row_key, col_key, cell_text)
5964
6002
 
6003
+ @with_full_df
5965
6004
  def cmd_select_row_above(self) -> None:
5966
6005
  """Select current row and all rows above it."""
5967
6006
  ridx = self.cursor_ridx
@@ -5971,6 +6010,7 @@ class DataFrameTable(DataTable):
5971
6010
  self.setup_table()
5972
6011
  self.notify(f"Selected [$success]{len(rids)}[/] row(s) (current + above)", title="Select Rows")
5973
6012
 
6013
+ @with_full_df
5974
6014
  def cmd_select_row_below(self) -> None:
5975
6015
  """Select current row and all rows below it."""
5976
6016
  ridx = self.cursor_ridx
@@ -6092,7 +6132,6 @@ class DataFrameTable(DataTable):
6092
6132
  self.notify("Failed to copy to clipboard", title="Copy to Clipboard", severity="error")
6093
6133
 
6094
6134
  # SQL Interface
6095
- @with_full_df
6096
6135
  def cmd_sql_simple(self) -> None:
6097
6136
  """Open the SQL interface screen."""
6098
6137
  self.app.push_screen(
@@ -6112,7 +6151,6 @@ class DataFrameTable(DataTable):
6112
6151
 
6113
6152
  self.run_sql(sql, new_tab)
6114
6153
 
6115
- @with_full_df
6116
6154
  def cmd_sql_advanced(self) -> None:
6117
6155
  """Open the advanced SQL interface screen."""
6118
6156
  self.app.push_screen(
@@ -6120,6 +6158,64 @@ class DataFrameTable(DataTable):
6120
6158
  callback=self.advanced_sql,
6121
6159
  )
6122
6160
 
6161
+ def advanced_sql(self, result) -> None:
6162
+ """Handle SQL result result from AdvancedSqlScreen."""
6163
+ if result is None:
6164
+ return
6165
+ sql, new_tab = result
6166
+
6167
+ self.run_sql(sql, new_tab)
6168
+
6169
+ @with_full_df
6170
+ def run_sql(self, sql: str, new_tab: bool = False) -> None:
6171
+ """Execute a SQL query directly.
6172
+
6173
+ Args:
6174
+ sql: The SQL query string to execute.
6175
+ new_tab: Whether to show results in a new tab or update the current view.
6176
+ """
6177
+ # handle special internal row identifier column references
6178
+ sql = sql.replace("RID", RID).replace("$#", f"(`{RID}` + 1)")
6179
+
6180
+ # Execute the SQL query
6181
+ try:
6182
+ df_filtered = add_rid_column(self.df.lazy().sql(sql)).collect()
6183
+ if len(df_filtered) == 0:
6184
+ self.notify(f"Query returned no results for [$warning]{sql}[/]", title="SQL Query", severity="warning")
6185
+ return
6186
+
6187
+ except Exception as e:
6188
+ self.notify(f"Failed to execute SQL query [$error]{sql}[/]", title="SQL Query", severity="error")
6189
+ self.log(f"Error executing SQL query `{sql}`: {e}")
6190
+ return
6191
+
6192
+ # Show results in new tab if requested
6193
+ if new_tab:
6194
+ return self.app.add_tab(
6195
+ df_filtered,
6196
+ filename="query_results.csv",
6197
+ tabname="query-results",
6198
+ after=self.app.tabbed.active_pane,
6199
+ )
6200
+
6201
+ # Add to history
6202
+ self.add_history(f"Run SQL Query: [$success]{sql}[/]")
6203
+
6204
+ # Store original dataframe in dfull if not already in a view
6205
+ if not self.in_view:
6206
+ self.dfull = self.df
6207
+
6208
+ # Update dataframe
6209
+ self.df = df_filtered
6210
+
6211
+ # Recreate table for display
6212
+ self.setup_table()
6213
+
6214
+ self.notify(
6215
+ f"Query executed successfully. Now showing [$accent]{len(self.df)}[/] rows and [$accent]{len(self.df.columns)}[/] columns.",
6216
+ title="SQL Query",
6217
+ )
6218
+
6123
6219
  def cmd_toggle_python_console(self) -> None:
6124
6220
  """Toggle the embedded Python console for the current tab."""
6125
6221
  console = self.app.console_panel
@@ -6193,61 +6289,3 @@ class DataFrameTable(DataTable):
6193
6289
  self.notify(f"Error calling {cmd_name}: {e}", title="Run Command", severity="error")
6194
6290
  except Exception as e:
6195
6291
  self.notify(f"{cmd_name} failed: {e}", title="Run Command", severity="error")
6196
-
6197
- def advanced_sql(self, result) -> None:
6198
- """Handle SQL result result from AdvancedSqlScreen."""
6199
- if result is None:
6200
- return
6201
- sql, new_tab = result
6202
-
6203
- self.run_sql(sql, new_tab)
6204
-
6205
- @with_full_df
6206
- def run_sql(self, sql: str, new_tab: bool = False) -> None:
6207
- """Execute a SQL query directly.
6208
-
6209
- Args:
6210
- sql: The SQL query string to execute.
6211
- new_tab: Whether to show results in a new tab or update the current view.
6212
- """
6213
- # handle special internal row identifier column references
6214
- sql = sql.replace("RID", RID).replace("$#", f"(`{RID}` + 1)")
6215
-
6216
- # Execute the SQL query
6217
- try:
6218
- df_filtered = add_rid_column(self.df.lazy().sql(sql)).collect()
6219
- if len(df_filtered) == 0:
6220
- self.notify(f"Query returned no results for [$warning]{sql}[/]", title="SQL Query", severity="warning")
6221
- return
6222
-
6223
- except Exception as e:
6224
- self.notify(f"Failed to execute SQL query [$error]{sql}[/]", title="SQL Query", severity="error")
6225
- self.log(f"Error executing SQL query `{sql}`: {e}")
6226
- return
6227
-
6228
- # Show results in new tab if requested
6229
- if new_tab:
6230
- return self.app.add_tab(
6231
- df_filtered,
6232
- filename="query_results.csv",
6233
- tabname="query-results",
6234
- after=self.app.tabbed.active_pane,
6235
- )
6236
-
6237
- # Add to history
6238
- self.add_history(f"Run SQL Query: [$success]{sql}[/]")
6239
-
6240
- # Store original dataframe in dfull if not already in a view
6241
- if not self.in_view:
6242
- self.dfull = self.df
6243
-
6244
- # Update dataframe
6245
- self.df = df_filtered
6246
-
6247
- # Recreate table for display
6248
- self.setup_table()
6249
-
6250
- self.notify(
6251
- f"Query executed successfully. Now showing [$accent]{len(self.df)}[/] rows and [$accent]{len(self.df.columns)}[/] columns.",
6252
- title="SQL Query",
6253
- )
@@ -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.0"
190
+ version = "3.1.2"
191
191
  source = { editable = "." }
192
192
  dependencies = [
193
193
  { name = "fastexcel" },