Skip to content

Conversation

@kkchemboli
Copy link
Contributor

@kkchemboli kkchemboli commented Oct 26, 2025

Describe your changes

This PR fixes a bug in the Streamlit DataEditor where columns containing lists (like a multiselect column) would raise a ValueError when rendering:
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions.

GitHub Issue Link (if applicable)

Fixes #12815

Testing Plan

  • Added unit test for Python

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.


Note

No changes in this PR.

Written by Cursor Bugbot for commit f08956b. This will update automatically on new commits. Configure here.

@snyk-io
Copy link
Contributor

snyk-io bot commented Oct 26, 2025

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Licenses 0 0 0 0 0 issues
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@kkchemboli kkchemboli closed this Oct 26, 2025
@kkchemboli kkchemboli reopened this Oct 26, 2025
@sfc-gh-lwilby sfc-gh-lwilby requested a review from Copilot October 27, 2025 11:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the Streamlit DataEditor where columns containing lists (like multiselect columns) would raise a ValueError during rendering due to pandas array assignment issues with sequences.

Key Changes:

  • Modified _apply_row_additions to wrap new row data in pd.Series with explicit column index alignment
  • Added comprehensive unit test to verify the fix works with multiselect columns

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
lib/streamlit/elements/widgets/data_editor.py Fixed row addition logic to properly handle list-type cells by wrapping assignments in pd.Series
lib/tests/streamlit/multiselect_column_test.py Added unit test verifying DataEditor works with multiselect columns containing list values

@@ -0,0 +1,77 @@
# Copyright (c) Streamlit Inc. (2018-2022) Snowflake Inc. (2022-2025)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Our tests are typically organized around the widget/element. Did you consider adding a test into data_editor_test.py?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for letting me know. Have moved the test into data_editor_test.py.

@kkchemboli kkchemboli force-pushed the array-shape-error-MultiselectColumn branch from b832e2f to 9bb1049 Compare October 27, 2025 15:07
@sfc-gh-lwilby sfc-gh-lwilby added security-assessment-completed Security assessment has been completed for PR change:bugfix PR contains bug fix implementation impact:users PR changes affect end users labels Oct 27, 2025
@sfc-gh-lwilby
Copy link
Collaborator

@kkchemboli thanks for creating this PR!

We had another issue come in where there was a silent failure when we start with an empty data editor. It could be a similar root cause, so I am wondering if you would be willing to test if your fix resolves this as well and if so add some test coverage for this? #12842

)

assert len(df) == 5
assert len(df["col5"].tolist()) == 5
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be good to strengthen this test by testing that the values are preserved correctly.

# Replace weak assertion:
 assert len(df["col5"].tolist()) == 5
 
 # With value verification:
 assert df.loc[3, "col5"] == ["x", "y"]
 assert df.loc[4, "col5"] == ["z"]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out . I've made the change.

@kkchemboli
Copy link
Contributor Author

@kkchemboli thanks for creating this PR!

We had another issue come in where there was a silent failure when we start with an empty data editor. It could be a similar root cause, so I am wondering if you would be willing to test if your fix resolves this as well and if so add some test coverage for this? #12842

I tested the case from #12842 (starting with an empty data editor), and it looks like my current fix doesn’t resolve that issue.

@kkchemboli
Copy link
Contributor Author

It looks like the CI run failed due to a timeout .Would it be possible to re-run the checks when you get a chance? Thanks!

@lukasmasuch
Copy link
Collaborator

@kkchemboli thanks for your contribution :) I looked into this as well, and I think using pd.Series might cause unexpected issues if used for rows with heterogeneous data types since it gets upcast to objects. I'm not sure how problematic it is in real-world scenarios. However, the solution here with dict feels a bit less risky: https://github.com/streamlit/streamlit/pull/12936/files

I will merge your PR into mine to give you co-contributor credits.

@lukasmasuch lukasmasuch changed the base branch from develop to fix/multiselect-col-shape-error November 5, 2025 19:56
@lukasmasuch lukasmasuch merged commit 8abaf76 into streamlit:fix/multiselect-col-shape-error Nov 5, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:bugfix PR contains bug fix implementation impact:users PR changes affect end users security-assessment-completed Security assessment has been completed for PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MultiselectColumn: inhomogeneous array shape error when adding new row to data editor with multiple columns

3 participants