Skip to content
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

Make default_display a global setting #121

Merged
merged 13 commits into from
Oct 25, 2020
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 @@ -572,7 +551,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