Allow different sorters to work with Vis Object#350
Allow different sorters to work with Vis Object#350jinimukh wants to merge 29 commits intolux-org:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #350 +/- ##
==========================================
+ Coverage 65.94% 66.24% +0.30%
==========================================
Files 55 56 +1
Lines 4416 4468 +52
==========================================
+ Hits 2912 2960 +48
- Misses 1504 1508 +4
Continue to review full report at Codecov.
|
lux/_config/config.py
Outdated
| from typing import Any, Callable, Dict, Iterable, List, Optional, Union | ||
| import lux | ||
| import warnings | ||
| from lux.utils.sorters import Sorter |
There was a problem hiding this comment.
Can we rename Sorter to something more specific? Currently, the sorter actually doesn't perform any sorting, but just returns the sort key, e.g. interestingness score, or sort key for alphabetical sorting.
| stacklevel=2, | ||
| ) | ||
|
|
||
| @property |
There was a problem hiding this comment.
Not sure if sort makes sense as a global option, since it is more common to do one type of sorting for an action, but a different sort mechanism for another action.
There was a problem hiding this comment.
I added two implementations -- one global ordering (this could be useful for sorting by attribute name or something really general that you want to standardize across all actions) and an action-wise ordering dictionary. If no ordering is defined for the specific action, then we fallback to the global ordering.
There was a problem hiding this comment.
This sounds great, let's add some docs that explain the two different types of ways to specify sorting!
tests/test_config.py
Outdated
| for vis in df.recommendation["Correlation"]: | ||
| assert vis.get_attr_by_channel("y")[0].attribute <= string | ||
| string = vis.get_attr_by_channel("y")[0].attribute | ||
| lux.config.sorter = "interestingness" |
There was a problem hiding this comment.
What is the difference between sorter and ordering?
lux/utils/orderings.py
Outdated
| return Ordering.interestingness | ||
| elif value == "title": | ||
| return Ordering.title | ||
| elif value == "x_attr": |
There was a problem hiding this comment.
can we make "title", "x_attr" and "y_attr" more readable? e.g.) "alphabetical_by_x", "alphabetical_by_y", "alphabetical_by_title"
| stacklevel=2, | ||
| ) | ||
|
|
||
| @property |
There was a problem hiding this comment.
This sounds great, let's add some docs that explain the two different types of ways to specify sorting!
dd380ca to
ecdd3ea
Compare
tests/test_config.py
Outdated
| def test_ordering_actions(global_var): | ||
| lux.config.topk = 5 | ||
|
|
||
| lux.config.ordering_actions["correlation"] = "x_attr" |
There was a problem hiding this comment.
The keys to "ordering_actions" is lowercase, would it break if the users specify uppercase ["Correlation"] instead?
| return self._ordering | ||
|
|
||
| @ordering.setter | ||
| def ordering(self, value): |
There was a problem hiding this comment.
Can we rename all ordering as ranking? We should avoid the word sorter in places where it might be unclear what it is referring it.
| import pandas as pd | ||
| import time | ||
| from lux.vis.VisList import VisList | ||
| from lux.utils.orderings import Ordering |
There was a problem hiding this comment.
Change orderings to ranking or sorter, it is more clear if we are consistent across the terminology used.
There was a problem hiding this comment.
I'll go for ranking because sort order (i.e. ascending/descending) uses "sort".
| ) | ||
|
|
||
| for vis in df.recommendation["Correlation"]: | ||
| assert ( |
There was a problem hiding this comment.
For every assert, we should add the error message to be thrown if the assertion does not pass.
| def sort_by_multiple(collection, desc): | ||
| collection.sort(key=lambda x: (x.get_attr_by_channel("x")[0].attribute, x.get_attr_by_channel("y")[0].attribute), reverse=False) | ||
| lux.config.ordering = sort_by_multiple | ||
|
|
There was a problem hiding this comment.
We didn't explain how lux.config.ordering can be used in the default case.
Overview
This PR introduces a way to incorporate different sorters for Vis Objects. Currently, this only includes interestingness and alphabetical sorts, but later on, we can extend this class.
Changes
-- add
sorters.pyin utils-- add
lux.config.sorterinconfig-- add tests in
test_configExample Output
TBD