Skip to content

Commit

Permalink
Fix Metadata Propagation with Overridden Pandas Methods (#332)
Browse files Browse the repository at this point in the history
* fix repr to display string of df

* replace repr_html to move widget into Out

* replace repr_html in other files

* fix issue for LuxSeries

* fix overridden pandas functions
  • Loading branch information
westernguy2 committed Apr 2, 2021
1 parent 2525d71 commit e96bf62
Showing 1 changed file with 48 additions and 50 deletions.
98 changes: 48 additions & 50 deletions lux/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,48 +624,48 @@ def _ipython_display_(self):
if self._pandas_only:
display(self.display_pandas())
self._pandas_only = False
# else:
if not self.index.nlevels >= 2 or self.columns.nlevels >= 2:
self.maintain_metadata()
else:
if not self.index.nlevels >= 2 or self.columns.nlevels >= 2:
self.maintain_metadata()

if self._intent != [] and (not hasattr(self, "_compiled") or not self._compiled):
from lux.processor.Compiler import Compiler
if self._intent != [] and (not hasattr(self, "_compiled") or not self._compiled):
from lux.processor.Compiler import Compiler

self.current_vis = Compiler.compile_intent(self, self._intent)
self.current_vis = Compiler.compile_intent(self, self._intent)

if lux.config.default_display == "lux":
self._toggle_pandas_display = False
else:
self._toggle_pandas_display = True
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()
# 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()

# Observers(callback_function, listen_to_this_variable)
self._widget.observe(self.remove_deleted_recs, names="deletedIndices")
self._widget.observe(self.set_intent_on_click, names="selectedIntentIndex")
# Observers(callback_function, listen_to_this_variable)
self._widget.observe(self.remove_deleted_recs, names="deletedIndices")
self._widget.observe(self.set_intent_on_click, names="selectedIntentIndex")

button = widgets.Button(
description="Toggle Pandas/Lux",
layout=widgets.Layout(width="140px", top="5px"),
)
self.output = widgets.Output()
display(button, self.output)

def on_button_clicked(b):
with self.output:
if b:
self._toggle_pandas_display = not self._toggle_pandas_display
clear_output()
if self._toggle_pandas_display:
display(self.display_pandas())
else:
# b.layout.display = "none"
display(self._widget)
# b.layout.display = "inline-block"

button.on_click(on_button_clicked)
on_button_clicked(None)
button = widgets.Button(
description="Toggle Pandas/Lux",
layout=widgets.Layout(width="140px", top="5px"),
)
self.output = widgets.Output()
display(button, self.output)

def on_button_clicked(b):
with self.output:
if b:
self._toggle_pandas_display = not self._toggle_pandas_display
clear_output()
if self._toggle_pandas_display:
display(self.display_pandas())
else:
# b.layout.display = "none"
display(self._widget)
# b.layout.display = "inline-block"

button.on_click(on_button_clicked)
on_button_clicked(None)

except (KeyboardInterrupt, SystemExit):
raise
Expand Down Expand Up @@ -884,24 +884,22 @@ def save_as_html(self, filename: str = "export.html") -> None:

# Overridden Pandas Functions
def head(self, n: int = 5):
self._prev = self
self._history.append_event("head", n=5)
return super(LuxDataFrame, self).head(n)
ret_val = super(LuxDataFrame, self).head(n)
ret_val._prev = self
ret_val._history.append_event("head", n=5)
return ret_val

def tail(self, n: int = 5):
self._prev = self
self._history.append_event("tail", n=5)
return super(LuxDataFrame, self).tail(n)

def info(self, *args, **kwargs):
self._pandas_only = True
self._history.append_event("info", *args, **kwargs)
return super(LuxDataFrame, self).info(*args, **kwargs)
ret_val = super(LuxDataFrame, self).tail(n)
ret_val._prev = self
ret_val._history.append_event("tail", n=5)
return ret_val

def describe(self, *args, **kwargs):
self._pandas_only = True
self._history.append_event("describe", *args, **kwargs)
return super(LuxDataFrame, self).describe(*args, **kwargs)
ret_val = super(LuxDataFrame, self).describe(*args, **kwargs)
ret_val._pandas_only = True
ret_val._history.append_event("describe", *args, **kwargs)
return ret_val

def groupby(self, *args, **kwargs):
history_flag = False
Expand Down

0 comments on commit e96bf62

Please sign in to comment.