dataframe-textual 3.1.0__tar.gz → 3.1.1__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.1}/PKG-INFO +1 -1
  2. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/pyproject.toml +1 -1
  3. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_table.py +100 -60
  4. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/uv.lock +1 -1
  5. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/.gitignore +0 -0
  6. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/LICENSE +0 -0
  7. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/README.md +0 -0
  8. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/main.py +0 -0
  9. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/__init__.py +0 -0
  10. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/__main__.py +0 -0
  11. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/commands.py +0 -0
  12. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/common.py +0 -0
  13. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/console_panel.py +0 -0
  14. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/data_frame_viewer.py +0 -0
  15. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/file_picker_screen.py +0 -0
  16. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/help_panel.py +0 -0
  17. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/keybindings.py +0 -0
  18. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/loading_screen.py +0 -0
  19. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/run_command_screen.py +0 -0
  20. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/status_bar.py +0 -0
  21. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/table_screen.py +0 -0
  22. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/text_screen.py +0 -0
  23. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/theme_screen.py +0 -0
  24. {dataframe_textual-3.1.0 → dataframe_textual-3.1.1}/src/dataframe_textual/yes_no_screen.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataframe-textual
3
- Version: 3.1.0
3
+ Version: 3.1.1
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.1"
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"
@@ -1319,50 +1319,86 @@ class DataFrameTable(DataTable):
1319
1319
  # self.app._set_status_context(self)
1320
1320
 
1321
1321
  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
1322
+ """Determine optimal width for each visible column based on data type and sampled content.
1323
+
1324
+ Algorithm (two phases):
1325
+
1326
+ **Phase 1 - initial widths:**
1327
+ - The column label width is always the floor (label is never clipped).
1328
+ - Bar columns are fixed to BAR_COLUMN_WIDTH.
1329
+ - User-overridden columns (positive width) are fixed to ``max(label, override)``.
1330
+ - URL-only string columns are skipped (let Textual auto-size so they stay clickable).
1331
+ - String columns whose sampled max exceeds COLUMN_WIDTH_CAP are capped at
1332
+ ``max(label_width, COLUMN_WIDTH_CAP)`` and queued for phase 2.
1333
+ - All other columns (numeric, bool, temporal, short strings, expanded columns)
1334
+ use their natural sampled max width.
1335
+
1336
+ **Phase 2 - expand capped columns with leftover space:**
1337
+ - Columns are processed in visible order.
1338
+ - If a column's ideal width fits in the remaining available space, expand it
1339
+ exactly to that width and move on.
1340
+ - If a column needs more than the remaining available space (it is "too wide"),
1341
+ distribute the remaining available space **evenly** among it and all
1342
+ subsequent capped columns, then stop.
1331
1343
 
1332
1344
  Returns:
1333
- dict[str, int]: Mapping of column name to width (None for auto-sizing columns).
1345
+ dict[str, int]: Mapping of column name to display width.
1334
1346
  """
1335
- col_widths, col_label_widths = {}, {}
1347
+ col_widths: dict[str, int] = {}
1348
+ col_label_widths: dict[str, int] = {}
1349
+ col_ideal_widths: dict[str, int] = {} # uncapped natural max from sampled data
1350
+ capped_cols: list[str] = [] # string cols capped in phase 1, in visible order
1336
1351
 
1352
+ # Pre-set bar columns
1337
1353
  for col in self.bar_columns:
1338
1354
  col_widths[col] = BAR_COLUMN_WIDTH
1339
1355
 
1340
- # Get available width for the table (with some padding for borders/scrollbar)
1356
+ # Available terminal width
1341
1357
  init_available_width = self.scrollable_content_region.width or self.app.size.width
1342
- available_width = init_available_width
1343
1358
 
1344
- # Sample a reasonable number of rows to calculate widths (don't scan entire dataframe)
1359
+ # Sample rows for width estimation
1345
1360
  sample_size = min(self.BATCH_SIZE, len(self.df))
1346
1361
  sample_lf = self.df.lazy().head(sample_size)
1347
1362
 
1348
- # Determine widths for each visible column
1363
+ # ── Phase 1: initial width for every visible column ───────────────────
1349
1364
  for col_idx, (col, dtype) in enumerate(self.visible_columns.items(), 1):
1350
- # Get column label width
1365
+ # Label width is the hard minimum
1351
1366
  label_text = self._build_column_label(col, col_idx)
1352
- label_width = measure(self.app.console, label_text, 1) + 2
1367
+ label_width = measure(self.app.console, label_text, 1)
1353
1368
  col_label_widths[col] = label_width
1354
1369
 
1355
- if label_width > col_widths.get(col, 0):
1356
- col_widths[col] = label_width
1370
+ # Bar columns: already fixed
1371
+ if col in self.bar_columns:
1372
+ col_ideal_widths[col] = col_widths[col]
1373
+ continue
1374
+
1375
+ # User-set fixed width: respect it
1376
+ if col in self.column_widths:
1377
+ override = self.column_widths[col]
1378
+ if override > 0:
1379
+ col_widths[col] = max(label_width, override)
1380
+ col_ideal_widths[col] = col_widths[col]
1381
+ continue
1382
+ # override == -1 means "expanded": fall through and skip the cap below
1383
+ # override == 0 means hidden: excluded from visible_columns already
1384
+
1385
+ dc = DtypeConfig(dtype)
1386
+ is_string = dc.gtype == "string"
1387
+ is_expanded = self.column_widths.get(col) == -1
1357
1388
 
1358
1389
  try:
1359
- # Get sample values from the column
1360
1390
  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
1391
 
1364
- # Find maximum width in sample
1365
- # For list columns, measure the string representation of the first three items to avoid extremely long widths
1392
+ # URL columns: leave for Textual auto-sizing so links stay clickable
1393
+ if (
1394
+ is_string
1395
+ and sample_values
1396
+ and any(val.startswith(("https://", "http://")) for val in sample_values)
1397
+ ):
1398
+ col_widths[col] = label_width
1399
+ col_ideal_widths[col] = label_width
1400
+ continue
1401
+
1366
1402
  max_cell_width = max(
1367
1403
  (
1368
1404
  measure(self.app.console, str(val[:3]) if isinstance(val, list) else str(val), 1)
@@ -1370,46 +1406,50 @@ class DataFrameTable(DataTable):
1370
1406
  ),
1371
1407
  default=label_width,
1372
1408
  )
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
1409
  except Exception as e:
1377
- # If any error, let Textual auto-size
1378
- max_width = label_width
1379
1410
  self.log(f"Error determining width for column `{col}`: {e}")
1411
+ max_cell_width = label_width
1380
1412
 
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
1413
+ ideal_width = max(label_width, max_cell_width)
1414
+ col_ideal_widths[col] = ideal_width
1415
+
1416
+ if is_string and not is_expanded and ideal_width > COLUMN_WIDTH_CAP:
1417
+ # Cap and queue for phase 2
1418
+ col_widths[col] = max(label_width, COLUMN_WIDTH_CAP)
1419
+ capped_cols.append(col)
1420
+ else:
1421
+ # Numeric / bool / temporal / short string / expanded: natural width
1422
+ col_widths[col] = ideal_width
1423
+
1424
+ # ── Phase 2: expand capped columns sequentially with leftover space ──
1425
+ available_width = init_available_width - sum(col_widths.values())
1426
+
1427
+ if available_width > 0 and capped_cols:
1428
+ # Only columns that can still grow
1429
+ expandable = [
1430
+ (col, col_ideal_widths[col] - col_widths[col])
1431
+ for col in capped_cols
1432
+ if col_ideal_widths.get(col, 0) > col_widths.get(col, 0)
1406
1433
  ]
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)
1434
+
1435
+ i = 0
1436
+ while i < len(expandable) and available_width > 0:
1437
+ col, needed = expandable[i]
1438
+
1439
+ if needed <= available_width:
1440
+ # Enough room: give the column exactly what it needs
1441
+ col_widths[col] += needed
1442
+ available_width -= needed
1443
+ i += 1
1444
+ else:
1445
+ # Column is too wide for remaining space: distribute
1446
+ # available_width evenly among this and all remaining capped columns
1447
+ remaining = expandable[i:]
1448
+ share = available_width // len(remaining)
1449
+ for rcol, _ in remaining:
1450
+ col_widths[rcol] += share
1451
+ available_width = 0
1452
+ break
1413
1453
 
1414
1454
  return col_widths
1415
1455
 
@@ -187,7 +187,7 @@ wheels = [
187
187
 
188
188
  [[package]]
189
189
  name = "dataframe-textual"
190
- version = "3.1.0"
190
+ version = "3.1.1"
191
191
  source = { editable = "." }
192
192
  dependencies = [
193
193
  { name = "fastexcel" },