Skip to content

Fix dataframe auto datatype for empty and 1D inputs#13361

Draft
fengfeng-zi wants to merge 1 commit intogradio-app:mainfrom
fengfeng-zi:fix/dataframe-auto-empty-13294
Draft

Fix dataframe auto datatype for empty and 1D inputs#13361
fengfeng-zi wants to merge 1 commit intogradio-app:mainfrom
fengfeng-zi:fix/dataframe-auto-empty-13294

Conversation

@fengfeng-zi
Copy link
Copy Markdown

@fengfeng-zi fengfeng-zi commented May 4, 2026

Summary

  • guard set_auto_datatype() against empty lists and 1D numpy arrays
  • fall back to "str" instead of indexing into unsupported shapes
  • add regression tests covering both empty list and 1D ndarray inputs

Closes #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 datatype falls 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.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 3c565e8. Configure here.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fix @fengfeng-zi

@freddyaboulton freddyaboulton marked this pull request as draft May 4, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gr.Dataframe with datatype="auto" crashes on empty list or 1D numpy array

2 participants