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

[sort] sort ordering is improperly copied in copy() #2190

Closed
midichef opened this issue Dec 24, 2023 · 2 comments · Fixed by #2192
Closed

[sort] sort ordering is improperly copied in copy() #2190

midichef opened this issue Dec 24, 2023 · 2 comments · Fixed by #2192
Labels

Comments

@midichef
Copy link
Contributor

midichef commented Dec 24, 2023

Small description
When I set a sort direction with [ and copy a sheet (as with "), the sort direction disappears in the new sheet,.

Expected result
I expect the sort columns to be preserved in the copy. Or to disappear in all cases.

Actual result with screenshot
Any ordering I create myself, is lost.
But some orderings are preserved in the copy, the built-in ones that use a column name (a string), instead of the column object. Like FreqTableSheet's 'count'.

Steps to reproduce with sample data and a .vd
Assign a sort direction to any column with [ and duplicate the sheet with g". The sort direction will not exist on the new sheet.

Additional context
visidata 2.11.1 and v3.0dev
The sort ordering is preserved across a copy, but too literally. After copy(), sheet._ordering contains columns, but they are the column objects from the source sheet, not the ones in the new copy. I can try to reconstruct the appropriate _ordering, like so:
f7bd9ef
But I run into a problem. The _ordering I make is later overwritten with an empty list. It happens because Extensible.init() runs the initfunc for _ordering, which is list. How should I handle that?

@saulpw
Copy link
Owner

saulpw commented Dec 25, 2023

So, the sort ordering is intended to be modular, which is why _ordering is created with Extensible.init(). Ideally everything using _ordering would be in sort.py, or strictly dependent on sort.py, and we're not that far from it (though it might be a little weird for part of sheet.drawColHeader to be in sort.py).

Let's try making Extensible newcopy not call the initializer if the attribute already exists (I just committed/pushed this). Your commit should work then. If not, we can let go of the above ideal, and remove the .init() and instead initialize it in the Sheet constructor. Maybe then we would make it a public interface and remove the leading _, or rename it to .sortCols. (Maybe we should do this anyway.)

@midichef
Copy link
Contributor Author

Okay, that makes sense, thanks for explaining the design goals.

The Extensible change works, so, I'll push a slightly modified version of the commit. I'd forgotten to handle the case where the sort column is a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants