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

Conversation

Future-Outlier
Copy link
Member

@Future-Outlier Future-Outlier commented Oct 2, 2024

Tracking issue

flyteorg/flyte#5792

Why are the changes needed?

if we install flytekitplugins-deck-standard and flytekit, when import flyetkit, it will raise an error about ModuleNotFoundError or ImportError

What changes were proposed in this pull request?

  1. add double quotes for pandas in pd.DataFrame as type hint.
  2. use import plotly.express as px in the function to_html for each class instead of using lazy import, since lazy import will require user to install plotly.

How was this patch tested?

Dependency Check

pip list | grep -iE "flyte|panda|mark|plotly|pillow|ydata|pygment"

flyteidl                                 1.13.5.dev12+gc0fc6d463             /Users/future-outlier/code/flyte/flyteidl
flytekit                                 1.13.6b3.dev46+gf50b1eeaa.d20240926
flytekitplugins-airflow                  0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-airflow
flytekitplugins-awssagemaker             0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-aws-sagemaker
flytekitplugins-bigquery                 0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-bigquery
flytekitplugins-deck-standard            0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-deck-standard
flytekitplugins-flyteinteractive         0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-flyteinteractive
flytekitplugins-openai                   0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-openai
flytekitplugins-snowflake                0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-snowflake
flytekitplugins-spark                    0.0.0+develop                       /Users/future-outlier/code/dev/flytekit/plugins/flytekit-spark
jupyterlab_pygments                      0.3.0
markdown-it-py                           3.0.0
MarkupSafe                               2.1.5
Pygments                                 2.18.0

Deck Example

import time

import flytekit
from flytekit import ImageSpec, task, workflow
from flytekitplugins.deck.renderer import FrameProfilingRenderer, BoxRenderer, ImageRenderer

flytekit_hash = "7344f3ad8398588c9cd3e57757ea8101fc131b8a"
flytekit = f"git+https://github.com/flyteorg/flytekit.git@{flytekit_hash}"
flytedeck_plugin = f"git+https://github.com/flyteorg/flytekit.git@{flytekit_hash}#subdirectory=plugins/flytekit-deck-standard"

# Define custom image for the task
custom_image = ImageSpec(packages=[flytekit, flytedeck_plugin],
                            apt_packages=["git"],
                            registry="localhost:30000",
                         )

# Task: Markdown Renderer
@task(enable_deck=True, container_image=custom_image)
def t_deck() -> None:
    # time.sleep(15)
    pass

@workflow
def wf() -> None:
    t_deck()

if __name__ == "__main__":
    from flytekit.clis.sdk_in_container import pyflyte
    from click.testing import CliRunner
    import os

    runner = CliRunner()
    path = os.path.realpath(__file__)
    result = runner.invoke(pyflyte.main,
                        ["run", path, "wf"])
    print("Local Execution: ", result.output)

    result = runner.invoke(pyflyte.main,
                           ["run", "--remote", path,"wf"])
    print("Remote Execution: ", result.output)

Setup process

local execution and remote execution.

Screenshots

  • local execution
image
  • remote execution
image image

Check all the applicable boxes

  • I updated the documentation accordingly.
  • All new and existing tests passed.
  • All commits are signed-off.

Related PRs

#2766

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

codecov bot commented Oct 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.61%. Comparing base (6e70129) to head (7344f3a).
Report is 2 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2783      +/-   ##
==========================================
+ Coverage   83.85%   91.61%   +7.76%     
==========================================
  Files           3      105     +102     
  Lines         161     5317    +5156     
==========================================
+ Hits          135     4871    +4736     
- Misses         26      446     +420     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Future-Outlier Future-Outlier enabled auto-merge (squash) October 2, 2024 04:02
@Future-Outlier Future-Outlier merged commit aa74f92 into master Oct 2, 2024
106 checks passed
@Future-Outlier Future-Outlier deleted the fix-deck-plugin branch October 2, 2024 04:06
@@ -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

@fellhorn
Copy link
Contributor

fellhorn commented Oct 2, 2024

Thanks @Future-Outlier 👍

otarabai pushed a commit to otarabai/flytekit that referenced this pull request Oct 15, 2024
* [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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants