Skip to content

DuckDBPyConnection.from_csv_auto typing not updated for file-like input #279

@peterpk

Description

@peterpk

What happens?

The type hint for DuckDBPyConnection.from_csv_auto includes this:

"path_or_buffer: str | bytes | PathLike[str] | PathLike[bytes]"

That only describes feeding it a path or filename, but not a file-like object (see duckdb/duckdb#6568). Passing a file-like object (such as io.StringIO) results in a type-checking error (Pylance, in my case).

To Reproduce

import duckdb
from io import StringIO

string = StringIO("c1,c2,c3\na,b,c")
duckdb.read_csv(string, header=True)

Pylance flags the string parameter in the last line with:

Argument of type "StringIO" cannot be assigned to parameter "path_or_buffer" of type "str | bytes | PathLike[str]" in function "read_csv"
  Type "StringIO" is not assignable to type "str | bytes | PathLike[str]"
    "StringIO" is not assignable to "str"
    "StringIO" is not assignable to "bytes"
    "StringIO" is incompatible with protocol "PathLike[str]"
      "__fspath__" is not present

OS:

Windows 11 x86_64

DuckDB Package Version:

1.4.3

Python Version:

3.14.2

Full Name:

Peter Kidwell

Affiliation:

The Boeing Company

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a stable release

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration to reproduce the issue?

  • Yes, I have

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions