mirror of
https://github.com/gradio-app/gradio.git
synced 2025-03-25 12:10:31 +08:00
Support empty lists being used in gr.Dataframe
(#3646)
* Support empty lists being used in `gr.Dataframe` * Update changelog * Add empty dataframe test --------- Co-authored-by: Abubakar Abid <abubakar@huggingface.co>
This commit is contained in:
parent
ae4277a9a8
commit
212961ef6a
@ -16,6 +16,7 @@
|
||||
- Fixed bug where chatbot does not autoscroll inside of a tab, row or column by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3637](https://github.com/gradio-app/gradio/pull/3637)
|
||||
- Fixed bug where textbox shrinks when `lines` set to larger than 20 by [@dawoodkhan82](https://github.com/dawoodkhan82) in [PR 3637](https://github.com/gradio-app/gradio/pull/3637)
|
||||
- Ensure CSS has fully loaded before rendering the application, by [@pngwn](https://github.com/pngwn) in [PR 3573](https://github.com/gradio-app/gradio/pull/3573)
|
||||
- Support using an empty list as `gr.Dataframe` value, by [@space-nuko](https://github.com/space-nuko) in [PR 3646](https://github.com/gradio-app/gradio/pull/3646)
|
||||
|
||||
## Documentation Changes:
|
||||
|
||||
|
@ -2878,6 +2878,8 @@ class Dataframe(Changeable, Selectable, IOComponent, JSONSerializable):
|
||||
),
|
||||
}
|
||||
if isinstance(y, (np.ndarray, list)):
|
||||
if len(y) == 0:
|
||||
return self.postprocess([[]])
|
||||
if isinstance(y, np.ndarray):
|
||||
y = y.tolist()
|
||||
assert isinstance(y, list), "output cannot be converted to list"
|
||||
|
@ -1096,6 +1096,8 @@ class TestDataframe:
|
||||
postprocess
|
||||
"""
|
||||
dataframe_output = gr.Dataframe()
|
||||
output = dataframe_output.postprocess([])
|
||||
assert output == {"data": [[]], "headers": []}
|
||||
output = dataframe_output.postprocess(np.zeros((2, 2)))
|
||||
assert output == {"data": [[0, 0], [0, 0]], "headers": [1, 2]}
|
||||
output = dataframe_output.postprocess([[1, 3, 5]])
|
||||
|
Loading…
x
Reference in New Issue
Block a user