Skip to content

feat: dataframe download separator#8318

Merged
mscolnick merged 3 commits intomarimo-team:mainfrom
vavavavavavavavava:feat/dataframe-download-separator
Mar 2, 2026
Merged

feat: dataframe download separator#8318
mscolnick merged 3 commits intomarimo-team:mainfrom
vavavavavavavavava:feat/dataframe-download-separator

Conversation

@vavavavavavavavava
Copy link
Contributor

📝 Summary

Add configurable CSV separator support to dataframe downloads, with consistent behavior across table backends.
Closes #7353

🔍 Description of Changes

This PR adds download_csv_separator to mo.ui.dataframe(...) and threads it through the full CSV download path so user-provided separators are respected end-to-end.

What changed

  • Added new dataframe option:
    • download_csv_separator: str | None = None
  • Propagated separator through:
    • dataframe download handler
    • download_as(...)
    • TableManager.to_csv(...) / to_csv_str(...)
    • backend table managers (default / narwhals / pandas / polars)

Backend behavior

  • pandas: passes separator to DataFrame.to_csv(sep=...)
  • polars: passes separator to write_csv(separator=...) (including fallback conversion path)
  • narwhals utility:
    • keeps native write_csv() for default comma
    • uses Python csv.writer for non-comma separators to avoid backend-specific inconsistency
  • default table manager: forwards separator to delegated manager

Why

write_csv(separator=...) is not consistently reliable across all narwhals-backed dataframe combinations.
This change makes non-comma CSV output predictable while preserving existing default behavior.

Backward compatibility

  • Default behavior is unchanged (comma-separated CSV).
  • Existing callers continue to work without modification.
  • New behavior is opt-in via download_csv_separator.

Example

import marimo as mo
import pandas as pd

df = pd.DataFrame({"name": ["Alice", "Bob"], "value": [1, 2]})

# Before: default download behavior
mo.ui.dataframe(df, show_download=True)

# After: configurable CSV encoding / separator and JSON escaping
mo.ui.dataframe(
    df,
    show_download=True,
    download_csv_separator=";",
)

Tests

Added/updated tests for:

  • dataframe CSV download with custom separator
  • dataframe_to_csv(..., separator=";") behavior across dataframe backends

📋 Checklist

@vercel
Copy link

vercel bot commented Feb 14, 2026

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

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Feb 14, 2026 2:47pm

Request Review

download_csv_encoding (str | None, optional): Encoding used when downloading CSV.
Defaults to the runtime config value (or "utf-8" if not configured).
Set to "utf-8-sig" to include BOM for Excel.
download_csv_separator (str | None, optional): Separator used in CSV downloads.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thoughts on just "download_separator" ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose download_csv_separator for consistency with download_csv_encoding. Since both options are specific to CSV downloads, I thought keeping the csv prefix makes the API clearer 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @dmadisetti

Just wanted to gently follow up on this — happy to rename it to download_separator if you think that’s preferable.

Let me know what you’d like, and I’ll update the PR accordingly. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@vavavavavavavavava im happy with download_csv_separator but i will make sure we get everyones sign-off

@mscolnick mscolnick added api-change enhancement New feature or request labels Feb 22, 2026
@mscolnick mscolnick requested a review from dmadisetti March 2, 2026 14:54
Copy link
Collaborator

@dmadisetti dmadisetti left a comment

Choose a reason for hiding this comment

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

My concern was download_csv_separator == "download comma separated value separator"

But I do think this is fine for consistency!

@mscolnick mscolnick merged commit 35e0c85 into marimo-team:main Mar 2, 2026
40 of 43 checks passed
@github-actions
Copy link

github-actions bot commented Mar 2, 2026

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

@vavavavavavavavava
Copy link
Contributor Author

@dmadisetti
@mscolnick

Thanks for the review and merge — much appreciated!

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

Labels

api-change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Allow configuring encoding for mo.ui.dataframe() download button

3 participants