Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empty lists being used in gr.Dataframe #3646

Merged
merged 4 commits into from
Mar 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions gradio/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,8 @@ def postprocess(
),
}
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"
Expand Down
2 changes: 2 additions & 0 deletions test/test_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,8 @@ def test_postprocess(self):
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]])
Expand Down