Lazy-import pandas (#7851)

* Lazy-import pandas

* add changeset

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Yuichiro Tachibana (Tsuchiya) 2024-03-28 04:13:48 +09:00 committed by GitHub
parent 7af3cd7ccb
commit e3b12369b7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 8 deletions

View File

@ -0,0 +1,5 @@
---
"gradio": patch
---
feat:Lazy-import pandas

View File

@ -2,13 +2,15 @@
from __future__ import annotations
from typing import Any, Callable, Literal
from typing import TYPE_CHECKING, Any, Callable, Literal
import pandas as pd
from gradio_client.documentation import document
from gradio.components.plot import AltairPlot, AltairPlotData, Plot
if TYPE_CHECKING:
import pandas as pd
@document()
class BarPlot(Plot):
@ -304,4 +306,6 @@ class BarPlot(Plot):
return None
def example_value(self) -> Any:
import pandas as pd
return pd.DataFrame({self.x: [1, 2, 3], self.y: [4, 5, 6]})

View File

@ -16,7 +16,6 @@ from typing import (
)
import numpy as np
import pandas as pd
import semantic_version
from gradio_client.documentation import document
@ -25,6 +24,7 @@ from gradio.data_classes import GradioModel
from gradio.events import Events
if TYPE_CHECKING:
import pandas as pd
import polars as pl # type: ignore
from pandas.io.formats.style import Styler
@ -191,6 +191,8 @@ class Dataframe(Component):
Returns:
Passes the uploaded spreadsheet data as a `pandas.DataFrame`, `numpy.array`, `polars.DataFrame`, or native 2D Python `list[list]` depending on `type`
"""
import pandas as pd
if self.type == "pandas":
if payload.headers is not None:
return pd.DataFrame(
@ -236,6 +238,7 @@ class Dataframe(Component):
Returns:
the uploaded spreadsheet data as an object with `headers` and `data` attributes
"""
import pandas as pd
from pandas.io.formats.style import Styler
if value is None:
@ -367,6 +370,8 @@ class Dataframe(Component):
| str
| None,
):
import pandas as pd
if value is None:
return ""
value_df_data = self.postprocess(value)

View File

@ -2,13 +2,15 @@
from __future__ import annotations
from typing import Any, Callable, Literal
from typing import TYPE_CHECKING, Any, Callable, Literal
import pandas as pd
from gradio_client.documentation import document
from gradio.components.plot import AltairPlot, AltairPlotData, Plot
if TYPE_CHECKING:
import pandas as pd
@document()
class LinePlot(Plot):
@ -336,4 +338,6 @@ class LinePlot(Plot):
return None
def example_value(self) -> Any:
import pandas as pd
return pd.DataFrame({self.x: [1, 2, 3], self.y: [4, 5, 6]})

View File

@ -2,14 +2,15 @@
from __future__ import annotations
from typing import Any, Callable, Literal
from typing import TYPE_CHECKING, Any, Callable, Literal
import pandas as pd
from gradio_client.documentation import document
from pandas.api.types import is_numeric_dtype
from gradio.components.plot import AltairPlot, AltairPlotData, Plot
if TYPE_CHECKING:
import pandas as pd
@document()
class ScatterPlot(Plot):
@ -231,6 +232,7 @@ class ScatterPlot(Plot):
):
"""Helper for creating the scatter plot."""
import altair as alt
from pandas.api.types import is_numeric_dtype
interactive = True if interactive is None else interactive
encodings = {
@ -360,4 +362,6 @@ class ScatterPlot(Plot):
return None
def example_value(self) -> Any:
import pandas as pd
return pd.DataFrame({self.x: [1, 2, 3], self.y: [4, 5, 6]})