@@ -4757,6 +4757,14 @@ def insert(
4757
4757
if not isinstance (loc , int ):
4758
4758
raise TypeError ("loc must be int" )
4759
4759
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
+
4760
4768
value = self ._sanitize_column (value )
4761
4769
self ._mgr .insert (loc , column , value )
4762
4770
@@ -4843,11 +4851,9 @@ def _sanitize_column(self, value) -> ArrayLike:
4843
4851
"""
4844
4852
self ._ensure_valid_index (value )
4845
4853
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 ):
4851
4857
return _reindex_for_setitem (Series (value ), self .index )
4852
4858
4853
4859
if is_list_like (value ):
0 commit comments