Skip to content

Commit 33d7a3e

Browse files
committed
EHN: Improve from_items error message (pandas-dev#17312)
1 parent be66ef8 commit 33d7a3e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pandas/core/frame.py

+7
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,13 @@ def from_items(cls, items, columns=None, orient='columns'):
12551255
"""
12561256
keys, values = lzip(*items)
12571257

1258+
import array
1259+
for val in values:
1260+
if not isinstance(val, (list, Series, np.ndarray, Categorical,
1261+
array.array)):
1262+
raise TypeError('The value in each (key, value) pair must '
1263+
'be an array or a Series')
1264+
12581265
if orient == 'columns':
12591266
if columns is not None:
12601267
columns = _ensure_index(columns)

pandas/tests/frame/test_constructors.py

+6
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,12 @@ def test_constructor_from_items(self):
12041204
columns=['one', 'two', 'three'])
12051205
tm.assert_frame_equal(rs, xp)
12061206

1207+
# GH 17312
1208+
with tm.assert_raises_regex(TypeError,
1209+
'The value in each \(key, value\) '
1210+
'pair must be an array or a Series'):
1211+
DataFrame.from_items([('A', 1), ('B', 4)])
1212+
12071213
def test_constructor_mix_series_nonseries(self):
12081214
df = DataFrame({'A': self.frame['A'],
12091215
'B': list(self.frame['B'])}, columns=['A', 'B'])

0 commit comments

Comments
 (0)