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

[Flyte Deck] Fix Lazy Import Error for Pandas and Plotly #2783

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means we need plotly as a hard dependency on the deck plugin, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, this means if we import BoxRenderer and use it in our task, this will be a required dependency


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
Loading