@@ -1426,8 +1426,7 @@ def _set_item(self, key, value):
1426
1426
Series/TimeSeries will be conformed to the DataFrame's index to
1427
1427
ensure homogeneity.
1428
1428
"""
1429
- value = self ._sanitize_column (value )
1430
- value = np .atleast_2d (value )
1429
+ value = self ._sanitize_column (key , value )
1431
1430
NDFrame ._set_item (self , key , value )
1432
1431
1433
1432
def insert (self , loc , column , value ):
@@ -1442,11 +1441,10 @@ def insert(self, loc, column, value):
1442
1441
column : object
1443
1442
value : int, Series, or array-like
1444
1443
"""
1445
- value = self ._sanitize_column (value )
1446
- value = np .atleast_2d (value )
1444
+ value = self ._sanitize_column (column , value )
1447
1445
self ._data .insert (loc , column , value )
1448
1446
1449
- def _sanitize_column (self , value ):
1447
+ def _sanitize_column (self , key , value ):
1450
1448
# Need to make sure new columns (which go into the BlockManager as new
1451
1449
# blocks) are always copied
1452
1450
if _is_sequence (value ):
@@ -1465,8 +1463,14 @@ def _sanitize_column(self, value):
1465
1463
value = value .copy ()
1466
1464
else :
1467
1465
value = np .repeat (value , len (self .index ))
1468
-
1469
- return np .asarray (value )
1466
+ if key in self .columns :
1467
+ existing_column = self [key ]
1468
+ # special case for now
1469
+ if (com .is_float_dtype (existing_column ) and
1470
+ com .is_integer_dtype (value )):
1471
+ value = value .astype (np .float64 )
1472
+
1473
+ return np .atleast_2d (np .asarray (value ))
1470
1474
1471
1475
def pop (self , item ):
1472
1476
"""
0 commit comments