mirror of
https://github.com/gradio-app/gradio.git
synced 2025-04-12 12:40:29 +08:00
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:
parent
7af3cd7ccb
commit
e3b12369b7
5
.changeset/sixty-buses-know.md
Normal file
5
.changeset/sixty-buses-know.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
feat:Lazy-import pandas
|
@ -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]})
|
||||
|
@ -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)
|
||||
|
@ -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]})
|
||||
|
@ -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]})
|
||||
|
Loading…
x
Reference in New Issue
Block a user