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:
space-nuko 2023-03-27 18:55:11 -05:00 committed by GitHub
parent ae4277a9a8
commit 212961ef6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 0 deletions

View File

@ -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:

View File

@ -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"

View File

@ -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]])