Skip to content

Commit

Permalink
[Flyte Deck] Fix Lazy Import Error for Pandas and Plotly (#2783)
Browse files Browse the repository at this point in the history
* [Flyte Deck] Fix Lazy Import Error for Pandas and Ploty

Signed-off-by: Future-Outlier <[email protected]>

* update fix

Signed-off-by: Future-Outlier <[email protected]>

---------

Signed-off-by: Future-Outlier <[email protected]>
  • Loading branch information
Future-Outlier authored Oct 2, 2024
1 parent 82276d9 commit aa74f92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 8 additions & 4 deletions plugins/flytekit-deck-standard/flytekitplugins/deck/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@
import markdown
import pandas as pd
import PIL.Image
import plotly.express as px
import pygments
import ydata_profiling
else:
pd = lazy_module("pandas")
markdown = lazy_module("markdown")
px = lazy_module("plotly.express")
PIL = lazy_module("PIL")
ydata_profiling = lazy_module("ydata_profiling")
pygments = lazy_module("pygments")
Expand Down Expand Up @@ -96,6 +94,8 @@ def __init__(self, column_name):
self._column_name = column_name

def to_html(self, df: "pd.DataFrame") -> str:
import plotly.express as px

fig = px.box(df, y=self._column_name)
return fig.to_html()

Expand Down Expand Up @@ -135,7 +135,9 @@ class TableRenderer:
Convert a pandas DataFrame into an HTML table.
"""

def to_html(self, df: pd.DataFrame, header_labels: Optional[List] = None, table_width: Optional[int] = None) -> str:
def to_html(
self, df: "pd.DataFrame", header_labels: Optional[List] = None, table_width: Optional[int] = None
) -> str:
# Check if custom labels are provided and have the correct length
if header_labels is not None and len(header_labels) == len(df.columns):
df = df.copy()
Expand Down Expand Up @@ -184,7 +186,9 @@ class GanttChartRenderer:
- "Name": string (the name of the task or event)
"""

def to_html(self, df: pd.DataFrame, chart_width: Optional[int] = None) -> str:
def to_html(self, df: "pd.DataFrame", chart_width: Optional[int] = None) -> str:
import plotly.express as px

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Name", color="Name", width=chart_width)

fig.update_xaxes(
Expand Down
4 changes: 1 addition & 3 deletions plugins/flytekit-deck-standard/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

microlib_name = f"flytekitplugins-{PLUGIN_NAME}-standard"

plugin_requires = [
"flytekit",
]
plugin_requires = ["flytekit"]

__version__ = "0.0.0+develop"

Expand Down

0 comments on commit aa74f92

Please sign in to comment.