Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pandas/io/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,8 @@ def __init__(self, f, engine=None, **kwds):

if kwds.get('dialect') is not None:
dialect = kwds['dialect']
if dialect in csv.list_dialects():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check if isinstance(dialect, compat.string_types)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

csv.list_dialects() is a list of strings so the test should be more stringent already. Will add it if you think it's necessary.

dialect = csv.get_dialect(dialect)
kwds['delimiter'] = dialect.delimiter
kwds['doublequote'] = dialect.doublequote
kwds['escapechar'] = dialect.escapechar
Expand Down
9 changes: 9 additions & 0 deletions pandas/tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -5982,6 +5982,15 @@ def _check_df(df,cols=None):
cols = ['b','a']
_check_df(df,cols)

def test_read_csv_dialect(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to pandas/io/tests/test_parser.py

model after an existing test (put near the quoting tests)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved it to the right place I hope.

df = pd.DataFrame({'fruit':['apple'], 'vegetable':['broccoli']})
csv.register_dialect("mydialect", delimiter="\t")
with ensure_clean() as path:
df.to_csv(path, sep='\t')
rc = pd.read_csv(path, dialect='mydialect', index_col=0)
assert_frame_equal(df, rc)
csv.unregister_dialect("mydialect")

@slow
def test_to_csv_moar(self):
path = '__tmp_to_csv_moar__'
Expand Down