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

Conversation

midichef
Copy link
Contributor

@midichef midichef commented May 4, 2024

After merging sheets, cells in MergeColumn hold None for rows that were not present on the sheet that the MergeColumn came from. Visidata shows errors when those cells appear on screen:

test_merge.vdj.txt
cd sample_data; vd -p test_merge.vdj

File "/home/midichef/.pyenv/versions/3.12.2/lib/python3.12/site-packages/visidata/features/join.py", line 179, in <lambda>
    CellColorizer(0, 'color_diff', lambda s,c,r,v: c and r and isinstance(c, MergeColumn) and c.isDiff(r, v.value))
File "/home/midichef/.pyenv/versions/3.12.2/lib/python3.12/site-packages/visidata/features/join.py", line 170, in isDiff
    return col and value != col.getValue(row[col.sheet])
...
File "/home/midichef/.pyenv/versions/3.12.2/lib/python3.12/site-packages/visidata/utils.py", line 134, in getitemdeep
    return obj[k]
TypeError: 'NoneType' object is not subscriptable

The return statements in this PR could be shortened to a one-line conditional: return col and ((row[col.sheet] is None) or (value != col.getValue(row[col.sheet]). But I broke it up to multiple lines because I found row and col to be quite difficult objects to think about. In fact, I wanted to add a comment to describe what situation would make row[col.sheet] be None. But row comes from groupRowsByKey(), and it's complex enough that I'm not sure I can describe it correctly:

rowsByKey[key] = [

This change to isDiff() only silences the error. It doesn't actually change the color of the cells, for two reasons:

  1. color_diff is not set by default, so isDiff() has no visible effect.
  2. Even if color_diff is set, it would not be used for , because color_note_type takes precedence.

Copy link
Owner

@saulpw saulpw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, thanks for fixing this and expanding isDiff().

@saulpw
Copy link
Owner

saulpw commented May 21, 2024

I found row and col to be quite difficult objects to think about. In fact, I wanted to add a comment to describe what situation would make row[col.sheet] be None

groupRowsByKey() can certainly be confusing, but this should be pretty straightforward here. Each row on the joined sheet is a dict, with the key being the source sheet, and the value being the source row from that source sheet. So row[col.sheet] is None when there is no matching row from that sheet.

@anjakefala anjakefala merged commit 4d596a9 into saulpw:develop May 22, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants