Skip to content

Add support for path-like file name in to_csv and to_parquet#527

Open
leostimpfle wants to merge 1 commit into
duckdb:mainfrom
leostimpfle:pathlike-output
Open

Add support for path-like file name in to_csv and to_parquet#527
leostimpfle wants to merge 1 commit into
duckdb:mainfrom
leostimpfle:pathlike-output

Conversation

@leostimpfle

@leostimpfle leostimpfle commented Jul 2, 2026

Copy link
Copy Markdown

This PR adds support for os.PathLike output filenames in the DuckDBPyRelation.to_csv and DuckDBPyRelation.to_parquet methods.

Currently, only plain Python strings are supported which requires explicit casting of pathlib.Path objects.

from pathlib import Path
import duckdb

# On main this throws TypeError: to_csv(): incompatible function arguments.
duckdb.sql("SELECT 43").to_csv(Path("test.csv"))

# Support for plain strings is unaffected
duckdb.sql("SELECT 43").to_csv("test.csv")

# Other arguments throw: _duckdb.InvalidInputException: Invalid Input Error: Expected a str, bytes, or os.PathLike object for the file path, not 'int'
duckdb.sql("SELECT 43").to_csv(123)

The core change is the addition of PathToString which is used in DuckDBPyRelation::ToCSV and DuckDBPyRelation::ToParquet. I have added tests in tests/fast/api/test_to_csv.py and tests/fast/api/test_to_parquet.py for the new argument types.

@evertlammerts Please let me know any comments. I have a few further ideas on similar small-ish improvements to duckdb-python which I would love to work on. (Please let me know if I should always first open discussions before PRs.)

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.

1 participant