Skip to content

fix(table): preserve column order in DefaultTableManager select/drop#9235

Merged
kirangadhave merged 2 commits intomainfrom
kg/table-export-column-order
Apr 17, 2026
Merged

fix(table): preserve column order in DefaultTableManager select/drop#9235
kirangadhave merged 2 commits intomainfrom
kg/table-export-column-order

Conversation

@kirangadhave
Copy link
Copy Markdown
Member

@kirangadhave kirangadhave commented Apr 16, 2026

Closes #9219.

Summary

mo.ui.table with plain Python data (list[dict] / dict[str, list]) was scrambling column order on every export. The fix makes select_columns and drop_columns keep the caller's column order on both the row-major and column-major paths.

Cause
drop_columns did a set-difference, and the row-major select_columns iterated a set. Set order depends on PYTHONHASHSEED, so it was random.
Pandas/polars DataFrames weren't affected — they go through NarwhalsTableManager.drop_columns which defers to the DataFrame's own drop().

Tests

Four hypothesis property tests in test_default_table.py pin the invariant: for any column list and any drop/select subset, output order matches the original.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 16, 2026 8:39pm

Request Review

@kirangadhave kirangadhave added the bug Something isn't working label Apr 16, 2026
@kirangadhave kirangadhave requested a review from mscolnick April 16, 2026 20:20
@kirangadhave kirangadhave marked this pull request as ready for review April 16, 2026 20:20
@mscolnick mscolnick requested a review from Copilot April 16, 2026 20:27
Copy link
Copy Markdown
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

Fixes non-deterministic column reordering for mo.ui.table when backed by plain Python data structures (list[dict] and dict[str, list]) by making select_columns/drop_columns preserve caller/original column order. This addresses export/download scrambling caused by set iteration/differences.

Changes:

  • Update DefaultTableManager.select_columns to preserve requested column order for both row-major and column-major data.
  • Update DefaultTableManager.drop_columns to preserve original column order when dropping columns.
  • Add Hypothesis property tests asserting column-order invariants for select/drop in both data layouts.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
marimo/_plugins/ui/_impl/tables/default_table.py Makes column selection/dropping order-preserving for plain-Python table data.
tests/_plugins/ui/_impl/tables/test_default_table.py Adds property-based tests to lock in order-preservation behavior.

Comment thread tests/_plugins/ui/_impl/tables/test_default_table.py Outdated
Comment thread tests/_plugins/ui/_impl/tables/test_default_table.py Outdated
Comment thread marimo/_plugins/ui/_impl/tables/default_table.py Outdated
@kirangadhave kirangadhave merged commit b1acb2f into main Apr 17, 2026
43 checks passed
@kirangadhave kirangadhave deleted the kg/table-export-column-order branch April 17, 2026 13:21
@github-actions
Copy link
Copy Markdown

🚀 Development release published. You may be able to view the changes at https://marimo.app?v=0.23.2-dev44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mo.ui.table: Export does not preserve column order for list[dict] / dict[str, list] data

3 participants