Skip to content

Commit b498a5c

Browse files
committed
frame: exclude str from Iterable in constructor
1 parent d8f7fd5 commit b498a5c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

pandas/core/frame.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ def __init__(self, data=None, index=None, columns=None, dtype=None,
389389
else:
390390
mgr = self._init_ndarray(data, index, columns, dtype=dtype,
391391
copy=copy)
392-
elif isinstance(data, collections.Iterable):
392+
elif (isinstance(data, collections.Iterable)
393+
and not isinstance(data, str)):
393394
if not isinstance(data, collections.Sequence):
394395
data = list(data)
395396
if len(data) > 0:

pandas/tests/series/test_constructors.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ def __iter__(self):
166166
result = Series(Iter(), dtype='int64')
167167
assert_series_equal(result, expected)
168168

169+
def test_constructor_single_str(self):
170+
171+
expected = Series(['abc'])
172+
result = Series('abc')
173+
assert_series_equal(result, expected)
174+
169175
def test_constructor_list_like(self):
170176

171177
# make sure that we are coercing different

0 commit comments

Comments
 (0)