Skip to content

Commit c023df1

Browse files
committed
EHN: Improve from_items error message (pandas-dev#17312)
1 parent d80a4b8 commit c023df1

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
@@ -1256,6 +1256,13 @@ def from_items(cls, items, columns=None, orient='columns'):
12561256
"""
12571257
keys, values = lzip(*items)
12581258

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

pandas/tests/frame/test_constructors.py

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

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

0 commit comments

Comments
 (0)