We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 96cbc80 commit fa3511bCopy full SHA for fa3511b
pandas/tests/io/formats/test_to_csv.py
@@ -300,3 +300,19 @@ def test_to_csv_stdout_file(self):
300
output = sys.stdout.getvalue()
301
assert output == expected_ascii
302
assert not sys.stdout.closed
303
+
304
+ def test_to_csv_write_to_open_file(self):
305
+ # GH 21696
306
+ df = pd.DataFrame({'a': ['x', 'y', 'z']})
307
+ expected = '''\
308
+manual header
309
+x
310
+y
311
+z
312
+'''
313
+ with tm.ensure_clean('test.txt') as path:
314
+ with open(path, 'w') as f:
315
+ f.write('manual header\n')
316
+ df.to_csv(f, header=None, index=None)
317
+ with open(path, 'r') as f:
318
+ assert f.read() == expected
0 commit comments