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

Monkey-patch pygwalker.walk #2798

Merged
merged 4 commits into from
Nov 5, 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
2 changes: 2 additions & 0 deletions marimo/_output/formatters/formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from marimo._output.formatters.panel_formatters import PanelFormatter
from marimo._output.formatters.plotly_formatters import PlotlyFormatter
from marimo._output.formatters.pyecharts_formatters import PyechartsFormatter
from marimo._output.formatters.pygwalker_formatters import PygWalkerFormatter
from marimo._output.formatters.seaborn_formatters import SeabornFormatter
from marimo._output.formatters.structures import StructuresFormatter
from marimo._output.formatters.sympy_formatters import SympyFormatter
Expand All @@ -39,6 +40,7 @@
PandasFormatter.package_name(): PandasFormatter(),
PolarsFormatter.package_name(): PolarsFormatter(),
PyArrowFormatter.package_name(): PyArrowFormatter(),
PygWalkerFormatter.package_name(): PygWalkerFormatter(),
PlotlyFormatter.package_name(): PlotlyFormatter(),
SeabornFormatter.package_name(): SeabornFormatter(),
LeafmapFormatter.package_name(): LeafmapFormatter(),
Expand Down
24 changes: 24 additions & 0 deletions marimo/_output/formatters/pygwalker_formatters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 Marimo. All rights reserved.
from __future__ import annotations

from marimo._output.formatters.formatter_factory import FormatterFactory
from marimo._runtime.context.utils import running_in_notebook


class PygWalkerFormatter(FormatterFactory):
@staticmethod
def package_name() -> str:
return "pygwalker"

def register(self) -> None:
if running_in_notebook():
# monkey-patch pygwalker.walk to work in marimo;
# older versions of marimo may not have api.marimo, and not sure
# about pygwalker's API stability, so use a coarse try/except
try:
import pygwalker # type: ignore
from pygwalker.api.marimo import walk # type: ignore

pygwalker.walk = walk # type: ignore
except Exception:
pass
23 changes: 23 additions & 0 deletions marimo/_smoke_tests/pygwalker_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import marimo

__generated_with = "0.9.14"
app = marimo.App(width="medium")


@app.cell
def __():
import pygwalker

from vega_datasets import data
return data, pygwalker


@app.cell
def __(data, pygwalker):
df = data.iris()
pygwalker.walk(df)
return (df,)


if __name__ == "__main__":
app.run()
Loading