Skip to content

Commit a8744ce

Browse files
committed
1 parent 9f1ae9c commit a8744ce

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

pandas/io/parsers.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from __future__ import print_function
55
from pandas.compat import range, lrange, StringIO, lzip, zip, string_types, map
66
from pandas import compat
7+
from collections import defaultdict
78
import re
89
import csv
910
import warnings
@@ -2264,6 +2265,8 @@ def _get_empty_meta(columns, index_col, index_names, dtype=None):
22642265
if dtype is None:
22652266
dtype = {}
22662267
else:
2268+
if not isinstance(dtype, dict):
2269+
dtype = defaultdict(lambda: dtype)
22672270
# Convert column indexes to column names.
22682271
dtype = dict((columns[k] if com.is_integer(k) else k, v)
22692272
for k, v in compat.iteritems(dtype))

pandas/tests/frame/test_to_csv.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,3 +1108,9 @@ def test_to_csv_with_dst_transitions(self):
11081108
df.to_pickle(path)
11091109
result = pd.read_pickle(path)
11101110
assert_frame_equal(result, df)
1111+
1112+
def test_to_csv_empty_frame(self):
1113+
# GH12048
1114+
actual = read_csv(StringIO('A,B'), dtype=str)
1115+
expected = pd.DataFrame({'A': [], 'B': []}, dtype=str).reset_index(drop=True)
1116+
assert_frame_equal(actual, expected, check_names=False, check_index_type=False)

0 commit comments

Comments
 (0)