Skip to content

Commit

Permalink
Make default_display a global setting (#121)
Browse files Browse the repository at this point in the history
* remove and register action functions

* update changes inframe.py

* update changes inframe.py

* add documentation and changes

* indentation and comments

* new line

* globally defined default display works with warning

* no examples

* add back space

* new line

* uncomment docstring

Co-authored-by: Caitlyn Chen <caitlynachen@berkeley.edu>
  • Loading branch information
caitlynachen and Caitlyn Chen committed Oct 25, 2020
1 parent 16ded3a commit b825c51
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
3 changes: 2 additions & 1 deletion lux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
register_action,
remove_action,
actions,
update_actions
update_actions,
config,
)
1 change: 1 addition & 0 deletions lux/_config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
remove_action,
actions,
update_actions,
config,
)
29 changes: 28 additions & 1 deletion lux/_config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'''
from collections import namedtuple
from typing import Any, Callable, Dict, Iterable, List, Optional
import warnings

RegisteredOption = namedtuple("RegisteredOption", "name action display_condition args")

Expand Down Expand Up @@ -142,4 +143,30 @@ def is_callable(obj) -> bool:
if not callable(obj):
raise ValueError("Value must be a callable")
return True


class Config:

def __init__(self):
self._default_display = "pandas"

@property
def default_display(self):
return self._default_display

@default_display.setter
def default_display(self, type:str) -> None:
"""
Set the widget display to show Pandas by default or Lux by default
Parameters
----------
type : str
Default display type, can take either the string `lux` or `pandas` (regardless of capitalization)
"""
if (type.lower()=="lux"):
self._default_display = "lux"
elif (type.lower()=="pandas"):
self._default_display = "pandas"
else:
warnings.warn("Unsupported display type. Default display option should either be `lux` or `pandas`.",stacklevel=2)

config = Config()
26 changes: 4 additions & 22 deletions lux/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,27 +121,6 @@ def _set_item(self, key, value):
super(LuxDataFrame, self)._set_item(key, value)
self.expire_metadata()
self.expire_recs()
@property
def default_display(self):
if (self._default_pandas_display):
return "pandas"
else:
return "lux"
@default_display.setter
def default_display(self, type:str) -> None:
"""
Set the widget display to show Pandas by default or Lux by default
Parameters
----------
type : str
Default display type, can take either the string `lux` or `pandas` (regardless of capitalization)
"""
if (type.lower()=="lux"):
self._default_pandas_display = False
elif (type.lower()=="pandas"):
self._default_pandas_display = True
else:
warnings.warn("Unsupported display type. Default display option should either be `lux` or `pandas`.",stacklevel=2)
def _infer_structure(self):
# If the dataframe is very small and the index column is not a range index, then it is likely that this is an aggregated data
is_multi_index_flag = self.index.nlevels !=1
Expand Down Expand Up @@ -591,7 +570,10 @@ def _repr_html_(self):
from lux.processor.Compiler import Compiler
self.current_vis = Compiler.compile_intent(self, self._intent)

self._toggle_pandas_display = self._default_pandas_display # Reset to Pandas Vis everytime
if (lux.config.default_display == "lux"):
self._toggle_pandas_display = False
else:
self._toggle_pandas_display = True

# df_to_display.maintain_recs() # compute the recommendations (TODO: This can be rendered in another thread in the background to populate self._widget)
self.maintain_recs()
Expand Down

0 comments on commit b825c51

Please sign in to comment.