-
Notifications
You must be signed in to change notification settings - Fork 370
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
Allow different sorters to work with Vis Object #350
base: master
Are you sure you want to change the base?
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
@@ -6,6 +6,7 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -83,6 +85,23 @@ def sort(self, flag: Union[str]): | |||
stacklevel=2, | |||
) | |||
|
|||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we make "title", "x_attr" and "y_attr" more readable? e.g.) "alphabetical_by_x", "alphabetical_by_y", "alphabetical_by_title"
@@ -83,6 +85,23 @@ def sort(self, flag: Union[str]): | |||
stacklevel=2, | |||
) | |||
|
|||
@property |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -17,6 +17,7 @@ | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll go for ranking because sort order (i.e. ascending/descending) uses "sort".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok!
) | ||
|
||
for vis in df.recommendation["Correlation"]: | ||
assert ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.py
in utils-- add
lux.config.sorter
inconfig
-- add tests in
test_config
Example Output
TBD