Skip to content

Commit

Permalink
Merge pull request #2400 from midichef/merge_diff_empty
Browse files Browse the repository at this point in the history
[join-] prevent diff error for empty merge cells
  • Loading branch information
anjakefala committed May 22, 2024
2 parents b0b601f + 950725a commit 4d596a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
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

0 comments on commit 4d596a9

Please sign in to comment.