Skip to content

DOC/ENH: read_csv dialect parameters should accept string #8703

Closed
@thrasibule

Description

@thrasibule

According to the doc of read_sql, dialect can be string or a csv.Dialect instance.
However this is not the case. If you look at the code, it can only really take a csv.Dialect instance. i.e. this doesn't work:

fh = io.StringIO(u"pomme\tpoire\n1\t\2")
pd.read_csv(fh, dialect='excel-tab')

but, this works:

fh = io.StringIO(u"pomme\tpoire\n1\t\2")
pd.read_csv(fh, dialect=csv.get_dialect('excel-tab'))

I would expect it to be able to take any string returned by the csv.list_dialects() function, similar to the way csv.reader works. So we can either remove the mention of string from the doc, or make it work as intended by checking if the dialect string is part of csv.list_dialects(). Let me know if this makes sense and I'll submit a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugCompatpandas objects compatability with Numpy or Python functionsDocsIO Excelread_excel, to_excel

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions