-
Notifications
You must be signed in to change notification settings - Fork 974
feat: dataframe download separator#8318
Conversation
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:
dataframedownload handlerdownload_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.writerfor non-comma separators to avoid backend-specific inconsistency
- keeps native
- 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 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
- I have read the contributor guidelines.
- For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable). (Issue: Feature request: Allow configuring encoding for
mo.ui.dataframe()download button #7353) - Tests have been added for the changes made.
- Documentation has been updated where applicable, including docstrings for API changes.
- Pull request title is a good summary of the changes - it will be used in the release notes.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| 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. |
There was a problem hiding this comment.
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" ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
dmadisetti
left a comment
There was a problem hiding this 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!
|
Development release published. You may be able to view the changes at https://marimo.app?v=0.20.3-dev82 |
|
Thanks for the review and merge -- much appreciated! |