Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[join-] prevent diff error for empty merge cells #2400

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions tests/golden/pr2400.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
a b c Number Exile
d e f
1 ggg hhh iiii
2 jjj kkk llllllll
Daniel 1 True
Hananiah 2 True
Mishael 3 True
Azariah 4 True
Nebuchadnezzar 5
19 changes: 19 additions & 0 deletions tests/pr2400.vdj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!vd -p
{"sheet": "global", "col": null, "row": "disp_date_fmt", "longname": "set-option", "input": "%b %d, %Y", "keystrokes": "", "comment": null}
{"sheet": "global", "row": "disp_float_fmt", "longname": "set-option", "input": "%.05f", "keystrokes": ""}
{"sheet": "global", "row": "default_width", "longname": "set-option", "input": "50", "keystrokes": ""}
{"longname": "open-file", "input": "sample_data/test.fixed", "keystrokes": "o"}
{"longname": "open-file", "input": "sample_data/officials.jsonla", "keystrokes": "o"}
{"sheet": "test", "col": "", "row": "", "longname": "sheets-stack", "input": "", "keystrokes": "Shift+S", "comment": "open Sheets Stack: join or jump between the active sheets on the current stack"}
{"sheet": "sheets", "col": "", "row": "\u30adofficials", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open sheet referenced in current row"}
{"sheet": "officials", "col": "", "row": "", "longname": "sheets-stack", "input": "", "keystrokes": "Shift+S", "comment": "open Sheets Stack: join or jump between the active sheets on the current stack"}
{"sheet": "sheets", "col": "", "row": "\u30adsheets", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open sheet referenced in current row"}
{"sheet": "sheets", "col": "", "row": "\u30adofficials", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open sheet referenced in current row"}
{"sheet": "officials", "col": "Name", "row": "", "longname": "key-col", "input": "", "keystrokes": "!", "comment": "toggle current column as a key column"}
{"sheet": "officials", "col": "", "row": "", "longname": "sheets-stack", "input": "", "keystrokes": "Shift+S", "comment": "open Sheets Stack: join or jump between the active sheets on the current stack"}
{"sheet": "sheets", "col": "", "row": "\u30adtest", "longname": "open-row", "input": "", "keystrokes": "Enter", "comment": "open sheet referenced in current row"}
{"sheet": "test", "col": 0, "row": "", "longname": "key-col", "input": "", "keystrokes": "!", "comment": "toggle current column as a key column"}
{"sheet": "test", "col": "", "row": "", "longname": "sheets-stack", "input": "", "keystrokes": "Shift+S", "comment": "open Sheets Stack: join or jump between the active sheets on the current stack"}
{"sheet": "sheets", "col": "", "row": "\u30adtest", "longname": "stoggle-row", "input": "", "keystrokes": "t", "comment": "toggle selection of current row"}
{"sheet": "sheets", "col": "", "row": "\u30adofficials", "longname": "stoggle-row", "input": "", "keystrokes": "t", "comment": "toggle selection of current row"}
{"sheet": "sheets", "col": "", "row": "", "longname": "join-selected", "input": "merge", "keystrokes": "&", "comment": "merge selected sheets with visible columns from all, keeping rows according to jointype"}
7 changes: 6 additions & 1 deletion visidata/features/join.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ def putValue(self, row, value):

def isDiff(self, row, value):
col = list(self.cols.values())[0]
return col and value != col.getValue(row[col.sheet])
if not col:
return False
if row[col.sheet] is None:
return True
return value != col.getValue(row[col.sheet])


#### slicing and dicing
Expand Down Expand Up @@ -196,6 +200,7 @@ def loader(self):
self.setKeys(self.columns)

allcols = collections.defaultdict(dict) # colname: { sheet: origcol, ... }
# MergeColumn relies on allcols having sheets in this specific order
for sheetnum, vs in enumerate(sheets):
for c in vs.visibleCols:
if c not in self.sheetKeyCols[vs]:
Expand Down