Skip to content

add test case when to_csv argument is sys.stdout #21572

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

Merged
merged 7 commits into from
Jun 22, 2018
Merged
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
15 changes: 15 additions & 0 deletions pandas/tests/io/formats/test_to_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,3 +285,18 @@ def test_to_csv_string_array_utf8(self):
df.to_csv(path, encoding='utf-8')
with open(path, 'r') as f:
assert f.read() == expected_utf8

@tm.capture_stdout
def test_to_csv_stdout_file(self):
# GH 21561
df = pd.DataFrame([['foo', 'bar'], ['baz', 'qux']],
columns=['name_1', 'name_2'])
expected_ascii = '''\
,name_1,name_2
0,foo,bar
1,baz,qux
'''
df.to_csv(sys.stdout, encoding='ascii')
output = sys.stdout.getvalue()
assert output == expected_ascii
assert not sys.stdout.closed