@@ -1703,6 +1703,10 @@ def _setitem_with_indexer(self, indexer, value, name: str = "iloc"):
1703
1703
# maybe partial set
1704
1704
take_split_path = not self .obj ._mgr .is_single_block
1705
1705
1706
+ if not take_split_path and isinstance (value , ABCDataFrame ):
1707
+ # Avoid cast of values
1708
+ take_split_path = not value ._mgr .is_single_block
1709
+
1706
1710
# if there is only one block/type, still have to take split path
1707
1711
# unless the block is one-dimensional or it can hold the value
1708
1712
if not take_split_path and len (self .obj ._mgr .arrays ) and self .ndim > 1 :
@@ -2055,7 +2059,7 @@ def _setitem_single_block(self, indexer, value, name: str) -> None:
2055
2059
value = self ._align_series (indexer , Series (value ))
2056
2060
2057
2061
elif isinstance (value , ABCDataFrame ) and name != "iloc" :
2058
- value = self ._align_frame (indexer , value )
2062
+ value = self ._align_frame (indexer , value ). _values
2059
2063
2060
2064
# check for chained assignment
2061
2065
self .obj ._check_is_chained_assignment_possible ()
@@ -2291,7 +2295,7 @@ def ravel(i):
2291
2295
2292
2296
raise ValueError ("Incompatible indexer with Series" )
2293
2297
2294
- def _align_frame (self , indexer , df : DataFrame ):
2298
+ def _align_frame (self , indexer , df : DataFrame ) -> DataFrame :
2295
2299
is_frame = self .ndim == 2
2296
2300
2297
2301
if isinstance (indexer , tuple ):
@@ -2315,15 +2319,15 @@ def _align_frame(self, indexer, df: DataFrame):
2315
2319
if idx is not None and cols is not None :
2316
2320
2317
2321
if df .index .equals (idx ) and df .columns .equals (cols ):
2318
- val = df .copy (). _values
2322
+ val = df .copy ()
2319
2323
else :
2320
- val = df .reindex (idx , columns = cols ). _values
2324
+ val = df .reindex (idx , columns = cols )
2321
2325
return val
2322
2326
2323
2327
elif (isinstance (indexer , slice ) or is_list_like_indexer (indexer )) and is_frame :
2324
2328
ax = self .obj .index [indexer ]
2325
2329
if df .index .equals (ax ):
2326
- val = df .copy (). _values
2330
+ val = df .copy ()
2327
2331
else :
2328
2332
2329
2333
# we have a multi-index and are trying to align
@@ -2338,7 +2342,7 @@ def _align_frame(self, indexer, df: DataFrame):
2338
2342
"specifying the join levels"
2339
2343
)
2340
2344
2341
- val = df .reindex (index = ax ). _values
2345
+ val = df .reindex (index = ax )
2342
2346
return val
2343
2347
2344
2348
raise ValueError ("Incompatible indexer with DataFrame" )
0 commit comments