Skip to content

Sort numeric text columns by value in the cluster tables - #1406

Merged
rossant merged 1 commit into
cortex-lab:masterfrom
adityasingh2400:fix/1405-numeric-column-sort
Aug 9, 2026
Merged

Sort numeric text columns by value in the cluster tables#1406
rossant merged 1 commit into
cortex-lab:masterfrom
adityasingh2400:fix/1405-numeric-column-sort

Conversation

@adityasingh2400

Copy link
Copy Markdown
Contributor

Sorting the Cluster View by the channel column ch orders 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 ch holds a channel label, and TemplateController.get_best_channel_label formats it with f'{ch}', so the value stored in the table is a string. _TableProxyModel.lessThan compares 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 just ch.

This adds _text_sort_key, used by lessThan when 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 to phy/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, and pytest phy/gui/tests/test_widgets.py phy/cluster/tests/test_supervisor.py all pass, 106 tests.

Fixes #1405

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
@rossant
rossant merged commit 1e56305 into cortex-lab:master Aug 9, 2026
12 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.

Sorting the channel number doesn't work

2 participants