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

[dup-selected] Stack tracing related to sorting/diving #2254

Closed
frosencrantz opened this issue Jan 14, 2024 · 3 comments
Closed

[dup-selected] Stack tracing related to sorting/diving #2254

frosencrantz opened this issue Jan 14, 2024 · 3 comments

Comments

@frosencrantz
Copy link
Contributor

Small description
dup-selected stack tracing related to sorting/diving

Expected result
No stack, new sheet

Actual result with screenshot

https://asciinema.org/a/8vNNKLZ9KpAV91NDrVQSRTeso

Traceback (most recent call last):
File "/usr/lib/python3.9/site-packages/visidata/basesheet.py", line 211, in execCommand
escaped = super().execCommand2(cmd, vdglobals=vdglobals)
File "/usr/lib/python3.9/site-packages/visidata/extensible.py", line 79, in wrappedfunc
r = oldfunc(*args, **kwargs)
File "/usr/lib/python3.9/site-packages/visidata/basesheet.py", line 76, in execCommand2
exec(code, vdglobals, LazyChainMap(vd, self))
File "dup-selected", line 1, in <module>
'VisiData: a curses interface for exploring and arranging tabular data'
File "/usr/lib/python3.9/copy.py", line 84, in copy
return copier(x)
File "/usr/lib/python3.9/site-packages/visidata/extensible.py", line 30, in newcopy
ret = oldcopy(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/visidata/extensible.py", line 30, in newcopy
ret = oldcopy(self, *args, **kwargs)
File "/usr/lib/python3.9/site-packages/visidata/extensible.py", line 30, in newcopy
ret = oldcopy(self, *args, **kwargs)
[Previous line repeated 1 more time]
File "/usr/lib/python3.9/site-packages/visidata/sheets.py", line 339, in __copy__
ret._ordering.append((col_mapping[sortcol],reverse))
KeyError: <ItemColumn: a>

If you get an unexpected error, please include the full stack trace that you get with Ctrl-E.

Steps to reproduce with sample data and a .vd

echo '{"a":"b","c":["d"]}' | vd -f json
Then sort the sheet, pyobj-cell into the cell in column 'c', select the row, and then dup-select

In the vdj file below I added the dup-selected manually, so it is possible that line is fully correct.

#!vd -p
{"sheet": "global", "col": null, "row": "filetype", "longname": "set-option", "input": "json", "keystrokes": "", "comment": null}
{"longname": "open-file", "input": "-", "keystrokes": "o"}
{"sheet": "-", "col": "a", "row": "", "longname": "sort-asc", "input": "", "keystrokes": "[", "comment": "sort ascending by current column; replace any existing sort criteria"}
{"sheet": "-", "col": "c", "row": "0", "longname": "pyobj-cell", "input": "", "keystrokes": "zCtrl+Y", "comment": "open current cell as Python object"}
{"sheet": "-[0].c", "col": "", "row": "0", "longname": "select-row", "input": "", "keystrokes": "s", "comment": "select current row"}
{"sheet": "-[0].c", "col"", "col": "", "row": "", "longname": "dup-selected", "input": "", "keystrokes": "\"", "comment": "open duplicate sheet with only selected rows"}

Additional context
Please include the version of VisiData and Python. Latest develop. Python 3.9.2

@anjakefala anjakefala modified the milestones: 3.0.1, 3.0.2 Jan 14, 2024
@saulpw
Copy link
Owner

saulpw commented Jan 14, 2024

This has something to do with 44bd7ca. @midichef, any ideas?

@anjakefala anjakefala removed this from the 3.0.2 milestone Jan 14, 2024
@saulpw
Copy link
Owner

saulpw commented Jan 15, 2024

This was a tricky one. Thanks for filing, @frosencrantz.

@saulpw saulpw closed this as completed Jan 15, 2024
saulpw added a commit that referenced this issue Jan 15, 2024
Every sheet instance needs its own _ordering list, which orderBy modifies.
But _ordering is defined at the class level so it can be easily specified per class.
Now we make a copy of the class _ordering when a new sheet is instantiated, so that orderBy doesn't modify the class list.
anjakefala pushed a commit that referenced this issue Jan 15, 2024
Every sheet instance needs its own _ordering list, which orderBy modifies.
But _ordering is defined at the class level so it can be easily specified per class.
Now we make a copy of the class _ordering when a new sheet is instantiated, so that orderBy doesn't modify the class list.
anjakefala pushed a commit that referenced this issue Jan 15, 2024
Every sheet instance needs its own _ordering list, which orderBy modifies.
But _ordering is defined at the class level so it can be easily specified per class.
Now we make a copy of the class _ordering when a new sheet is instantiated, so that orderBy doesn't modify the class list.
@frosencrantz
Copy link
Contributor Author

@saulpw Thanks for fixing it! I was trying to make it a simpler case, that seemed to be the smallest case. I understand now why it required a trip through multiple sheets.

anjakefala pushed a commit that referenced this issue Jan 16, 2024
Every sheet instance needs its own _ordering list, which orderBy modifies.
But _ordering is defined at the class level so it can be easily specified per class.
Now we make a copy of the class _ordering when a new sheet is instantiated, so that orderBy doesn't modify the class list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants