Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Add 'names' option to read_csv #8967

Merged
merged 2 commits into from
Sep 18, 2023

Conversation

Tishj
Copy link
Contributor

@Tishj Tishj commented Sep 17, 2023

This PR fixes #8857

The PR also mentions auto_detect but that isn't supported.
read_csv will always auto detect currently.

We add support for the names parameter, as an Optional[List[str]], and this plays nicely with the existing dtype parameter.

Misc:

This PR also fixes a slight bug in dtype, as it cast the type parameter to DuckDBPyType but then didn't use this result, instead it just used str(type), which made dtype fail if anything other than a str | DuckDBPyType was provided.
Now things like int and str which can be implicitly cast to DuckDBPyType also work i.e

        rel = con.read_csv(
            file,
            names=['a', 'b', 'c'],
            dtype={
                'a': int,
                'b': bool,
                'c': str,
            },
        )

@github-actions github-actions bot marked this pull request as draft September 17, 2023 13:22
@Tishj Tishj marked this pull request as ready for review September 17, 2023 19:32
@Mytherin Mytherin merged commit 897986a into duckdb:main Sep 18, 2023
50 checks passed
@Mytherin
Copy link
Collaborator

Thanks!

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.

[python] read_csv() doesn't support the "names" or "auto_detect" parameters that the CLI/SQL function supports
2 participants