Sort numeric text columns by value in the cluster tables - #1406
Merged
rossant merged 1 commit intoAug 9, 2026
Conversation
The cluster and similarity views store channel labels as strings, so the table proxy model compared them character by character and placed '10' before '2'. Compare numeric text by numeric value instead, and keep non-numeric entries in their string order. Fixes cortex-lab#1405
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorting the Cluster View by the channel column
chorders channels as text rather than as numbers, so a single-digit channel lands in the wrong place relative to a two-digit one. Ascending order comes out as 1, 10, 2, 21, 3 instead of 1, 2, 3, 10, 21.The cause is that
chholds a channel label, andTemplateController.get_best_channel_labelformats it withf'{ch}', so the value stored in the table is a string._TableProxyModel.lessThancompares raw values with<, which for two strings is a character by character comparison. Every column whose values arrive as text has the same problem, not justch.This adds
_text_sort_key, used bylessThanwhen either side is a string. Entries that parse as numbers sort first and in numeric order, and the remaining entries keep their existing string ordering, so a mixed column such as a label column stays predictable. Non-string values keep the previous exact comparison path, so integer and float columns are unaffected.Verified headlessly against a table holding the channel labels 2, 10, 1, 21, 3. Before the change the ascending order was
['1', '10', '2', '21', '3'], after it is['1', '2', '3', '10', '21']. Two regression tests were added tophy/gui/tests/test_widgets.py, one for a purely numeric text column and one for a column mixing numbers and free text. Both fail on master and pass with the fix.make lint,make format-check, andpytest phy/gui/tests/test_widgets.py phy/cluster/tests/test_supervisor.pyall pass, 106 tests.Fixes #1405