mirror of
https://github.com/gradio-app/gradio.git
synced 2024-11-21 01:01:05 +08:00
Fix data model for gr.DataFrame
(#6310)
* datamodel for df * add changeset * fix * Add code * reduce * trigger ci * typing * union --------- Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: freddyaboulton <alfonsoboulton@gmail.com>
This commit is contained in:
parent
0db1e2546a
commit
dfdaf10926
5
.changeset/all-cougars-matter.md
Normal file
5
.changeset/all-cougars-matter.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"gradio": patch
|
||||
---
|
||||
|
||||
fix:Fix data model for `gr.DataFrame`
|
@ -19,9 +19,7 @@ from gradio.events import Events
|
||||
class DataframeData(GradioModel):
|
||||
headers: List[str]
|
||||
data: List[List[Any]]
|
||||
metadata: Optional[
|
||||
Dict[str, List[Any]]
|
||||
] = None # Optional[Dict[str, List[Any]]] = None
|
||||
metadata: Optional[Dict[str, Optional[List[Any]]]] = None
|
||||
|
||||
|
||||
set_documentation_group("component")
|
||||
@ -216,7 +214,7 @@ class Dataframe(Component):
|
||||
return DataframeData(
|
||||
headers=list(df.columns),
|
||||
data=df.to_dict(orient="split")["data"], # type: ignore
|
||||
metadata=self.__extract_metadata(value),
|
||||
metadata=self.__extract_metadata(value), # type: ignore
|
||||
)
|
||||
elif isinstance(value, (str, pd.DataFrame)):
|
||||
df = pd.read_csv(value) if isinstance(value, str) else value # type: ignore
|
||||
|
@ -997,6 +997,14 @@ class TestDataframe:
|
||||
dataframe_input = gr.Dataframe()
|
||||
output = dataframe_input.preprocess(DataframeData(**x_data))
|
||||
assert output["Age"][1] == 24
|
||||
|
||||
x_data = {
|
||||
"data": [["Tim", 12, False], ["Jan", 24, True]],
|
||||
"headers": ["Name", "Age", "Member"],
|
||||
"metadata": {"display_value": None, "styling": None},
|
||||
}
|
||||
dataframe_input.preprocess(DataframeData(**x_data))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
gr.Dataframe(type="unknown")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user