From b825c51d16a47dd4de83bf268b83c53d70454fdc Mon Sep 17 00:00:00 2001 From: Caitlyn Chen Date: Sat, 24 Oct 2020 23:38:02 -0700 Subject: [PATCH] Make default_display a global setting (#121) * 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 --- lux/__init__.py | 3 ++- lux/_config/__init__.py | 1 + lux/_config/config.py | 29 ++++++++++++++++++++++++++++- lux/core/frame.py | 26 ++++---------------------- 4 files changed, 35 insertions(+), 24 deletions(-) diff --git a/lux/__init__.py b/lux/__init__.py index 2d149806..8688b3d2 100644 --- a/lux/__init__.py +++ b/lux/__init__.py @@ -21,5 +21,6 @@ register_action, remove_action, actions, - update_actions + update_actions, + config, ) diff --git a/lux/_config/__init__.py b/lux/_config/__init__.py index 2d70a068..f7130949 100644 --- a/lux/_config/__init__.py +++ b/lux/_config/__init__.py @@ -4,4 +4,5 @@ remove_action, actions, update_actions, + config, ) diff --git a/lux/_config/config.py b/lux/_config/config.py index a5d6992f..12a7271b 100644 --- a/lux/_config/config.py +++ b/lux/_config/config.py @@ -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") @@ -142,4 +143,30 @@ def is_callable(obj) -> bool: if not callable(obj): raise ValueError("Value must be a callable") return True - \ No newline at end of file + +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() diff --git a/lux/core/frame.py b/lux/core/frame.py index 6ef8b775..27227bc3 100644 --- a/lux/core/frame.py +++ b/lux/core/frame.py @@ -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 @@ -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()