-
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?
Changes from 20 commits
2cef000
cad3e84
f197884
1ed9655
c56f79d
c0388df
cf045de
6ae9767
0db6376
1e6f572
7836abf
9c17abb
b3509f6
d428289
9716088
912f3cc
8041f84
9548b8a
e5f5aa4
0aa92a2
0b8ee08
31ec5a6
5aa2178
bd6d4b4
79e4a41
f9e34bc
ecdd3ea
0141fa1
d08c17c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
from typing import Any, Callable, Dict, Iterable, List, Optional, Union | ||
import lux | ||
import warnings | ||
from lux.utils.sorters import Sorter | ||
|
||
RegisteredOption = namedtuple("RegisteredOption", "name action display_condition args") | ||
|
||
|
@@ -32,6 +33,7 @@ def __init__(self): | |
self._plotting_backend = "vegalite" | ||
self._topk = 15 | ||
self._sort = "descending" | ||
self._sorter = Sorter.interestingness() | ||
self._pandas_fallback = True | ||
self._interestingness_fallback = True | ||
self.heatmap_bin_size = 40 | ||
|
@@ -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 commentThe 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 commentThe 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 commentThe 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! |
||
def sorter(self): | ||
return self._sorter | ||
|
||
@sorter.setter | ||
def sorter(self, sorting_function): | ||
""" | ||
Setting parameter to determine sort function of each action | ||
|
||
Parameters | ||
---------- | ||
flag : Union[str] | ||
"none", "ascending","descending" | ||
No sorting, sort by ascending order, sort by descending order | ||
""" | ||
self._sorter = sorting_function | ||
|
||
@property | ||
def pandas_fallback(self): | ||
return self._pandas_fallback | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Copyright 2019-2020 The Lux Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
class Sorter: | ||
@staticmethod | ||
def interestingness(): | ||
dorisjlee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return lambda x: x.score | ||
|
||
@staticmethod | ||
def title(): | ||
return lambda x: x.title | ||
|
||
@staticmethod | ||
def x_alpha(): | ||
return lambda x: x.get_attr_by_channel("x")[0].attribute | ||
|
||
@staticmethod | ||
def y_alpha(): | ||
return lambda x: x.get_attr_by_channel("y")[0].attribute |
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.