@@ -4757,6 +4757,14 @@ def insert(
47574757 if not isinstance (loc , int ):
47584758 raise TypeError ("loc must be int" )
47594759
4760+ if isinstance (value , DataFrame ) and len (value .columns ) > 1 :
4761+ raise ValueError (
4762+ f"Expected a one-dimensional object, got a DataFrame with "
4763+ f"{ len (value .columns )} columns instead."
4764+ )
4765+ elif isinstance (value , DataFrame ):
4766+ value = value .iloc [:, 0 ]
4767+
47604768 value = self ._sanitize_column (value )
47614769 self ._mgr .insert (loc , column , value )
47624770
@@ -4843,11 +4851,9 @@ def _sanitize_column(self, value) -> ArrayLike:
48434851 """
48444852 self ._ensure_valid_index (value )
48454853
4846- # We can get there through isetitem with a DataFrame
4847- # or through loc single_block_path
4848- if isinstance (value , DataFrame ):
4849- return _reindex_for_setitem (value , self .index )
4850- elif is_dict_like (value ):
4854+ # Using a DataFrame would mean coercing values to one dtype
4855+ assert not isinstance (value , DataFrame )
4856+ if is_dict_like (value ):
48514857 return _reindex_for_setitem (Series (value ), self .index )
48524858
48534859 if is_list_like (value ):
0 commit comments