Fix dataframe auto datatype for empty and 1D inputs#13361
Fix dataframe auto datatype for empty and 1D inputs#13361fengfeng-zi wants to merge 1 commit intogradio-app:mainfrom
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 3c565e8. Configure here.
| elif isinstance(value, list): | ||
| if len(value) == 0: | ||
| self.datatype = "str" | ||
| return |
There was a problem hiding this comment.
1D non-empty list still crashes in set_auto_datatype
High Severity
The list branch in set_auto_datatype only guards against empty lists but not 1D non-empty lists. The numpy branch correctly guards against both (value.ndim < 2 or value.size == 0), but a 1D list like [1, 2, 3] passes the len(value) == 0 check and reaches for val in value[0], which tries to iterate over an integer, raising a TypeError. The guard needs to also check whether value[0] is itself a list/iterable, mirroring the 1D protection added for numpy arrays.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 3c565e8. Configure here.


Summary
set_auto_datatype()against empty lists and 1D numpy arrays"str"instead of indexing into unsupported shapesCloses #13294
Testing
python -m pytest test/components/test_dataframe.py -k "auto_datatype_handles_empty_list_and_1d_ndarray or is_empty"Note
Low Risk
Low risk: adds simple guards in
set_auto_datatype()to avoid indexing errors on empty/1D inputs, plus focused regression tests.Overview
Fixes
gr.Dataframe(datatype="auto")inference for unsupported/empty shapes by treating empty lists and 1D/empty numpy arrays as a single"str"datatype instead of indexing into missing columns.Adds regression tests ensuring
datatypefalls back to"str"for these inputs.Reviewed by Cursor Bugbot for commit 3c565e8. Bugbot is set up for automated code reviews on this repo. Configure here.