Skip to content

Commit

Permalink
[features-] add command to hide repetitive columns
Browse files Browse the repository at this point in the history
  • Loading branch information
midichef committed Jul 13, 2024
1 parent 25d6997 commit 7239fc0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions visidata/features/dedupe.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,21 @@ def _reload(self=vs):
return vs


@Sheet.api
@asyncthread
def hide_unvarying_cols(sheet):
if len(sheet.rows) < 2:
return
for col in sheet.visibleCols:
vals = (col.getTypedValue(r) for r in sheet.rows)
first = next(vals)
if all(v == first for v in vals):
col.hide()

# Add longname-commands to VisiData to execute these methods
BaseSheet.addCommand(None, "select-duplicate-rows", "sheet.select_duplicate_rows()", "select each row that is a duplicate of a prior row")
BaseSheet.addCommand(None, "dedupe-rows", "vd.push(sheet.dedupe_rows())", "open new sheet in which only non-duplicate rows in the active sheet are included")
BaseSheet.addCommand(None, 'hide-unvarying-cols', 'sheet.hide_unvarying_cols()', 'hide any column that has multiple rows but only one distinct value')

vd.addMenuItems('''
Row > Select > duplicate rows > select-duplicate-rows
Expand Down

0 comments on commit 7239fc0

Please sign in to comment.