@@ -197,6 +197,7 @@ def blklocs(self) -> npt.NDArray[np.intp]:
197197 def make_empty (self , axes = None ) -> Self :
198198 """return an empty BlockManager with the items axis of len 0"""
199199 if axes is None :
200+ # TODO shallow copy remaining axis?
200201 axes = [Index ([])] + self .axes [1 :]
201202
202203 # preserve dtype if possible
@@ -355,6 +356,7 @@ def apply(
355356 applied = getattr (b , f )(** kwargs )
356357 result_blocks = extend_blocks (applied , result_blocks )
357358
359+ # TODO shallow copy axes (in from_blocks or here?)
358360 out = type (self ).from_blocks (result_blocks , self .axes )
359361 return out
360362
@@ -575,6 +577,7 @@ def get_numeric_data(self, copy: bool = False) -> Self:
575577 # Avoid somewhat expensive _combine
576578 if copy :
577579 return self .copy (deep = True )
580+ # TODO(CoW) need to return a shallow copy here?
578581 return self
579582 return self ._combine (numeric_blocks , copy )
580583
@@ -606,6 +609,7 @@ def _combine(
606609 new_blocks .append (nb )
607610
608611 axes = list (self .axes )
612+ # TODO shallow copy of axes?
609613 if index is not None :
610614 axes [- 1 ] = index
611615 axes [0 ] = self .items .take (indexer )
@@ -647,7 +651,10 @@ def copy_func(ax):
647651
648652 new_axes = [copy_func (ax ) for ax in self .axes ]
649653 else :
650- new_axes = list (self .axes )
654+ if using_copy_on_write ():
655+ new_axes = [ax .view () for ax in self .axes ]
656+ else :
657+ new_axes = list (self .axes )
651658
652659 res = self .apply ("copy" , deep = deep )
653660 res .axes = new_axes
@@ -674,6 +681,7 @@ def consolidate(self) -> Self:
674681 if self .is_consolidated ():
675682 return self
676683
684+ # TODO shallow copy is not needed here?
677685 bm = type (self )(self .blocks , self .axes , verify_integrity = False )
678686 bm ._is_consolidated = False
679687 bm ._consolidate_inplace ()
@@ -718,6 +726,7 @@ def reindex_indexer(
718726
719727 if indexer is None :
720728 if new_axis is self .axes [axis ] and not copy :
729+ # TODO(CoW) need to handle CoW?
721730 return self
722731
723732 result = self .copy (deep = copy )
@@ -756,6 +765,8 @@ def reindex_indexer(
756765
757766 new_axes = list (self .axes )
758767 new_axes [axis ] = new_axis
768+ if self .ndim == 2 and using_copy_on_write ():
769+ new_axes [1 - axis ] = self .axes [1 - axis ]._view ()
759770
760771 new_mgr = type (self ).from_blocks (new_blocks , new_axes )
761772 if axis == 1 :
@@ -1034,6 +1045,7 @@ def fast_xs(self, loc: int) -> SingleBlockManager:
10341045 ndim = 1 ,
10351046 refs = self .blocks [0 ].refs ,
10361047 )
1048+ # TODO shallow copy columns
10371049 return SingleBlockManager (block , self .axes [0 ])
10381050
10391051 dtype = interleaved_dtype ([blk .dtype for blk in self .blocks ])
@@ -1067,6 +1079,7 @@ def fast_xs(self, loc: int) -> SingleBlockManager:
10671079
10681080 bp = BlockPlacement (slice (0 , len (result )))
10691081 block = new_block (result , placement = bp , ndim = 1 )
1082+ # TODO shallow copy columns
10701083 return SingleBlockManager (block , self .axes [0 ])
10711084
10721085 def iget (self , i : int , track_ref : bool = True ) -> SingleBlockManager :
@@ -1081,6 +1094,7 @@ def iget(self, i: int, track_ref: bool = True) -> SingleBlockManager:
10811094 nb = type (block )(
10821095 values , placement = bp , ndim = 1 , refs = block .refs if track_ref else None
10831096 )
1097+ # TODO shallow copy index? (might already be done where this gets called)
10841098 return SingleBlockManager (nb , self .axes [1 ])
10851099
10861100 def iget_values (self , i : int ) -> ArrayLike :
@@ -1479,6 +1493,7 @@ def idelete(self, indexer) -> BlockManager:
14791493
14801494 nbs = self ._slice_take_blocks_ax0 (taker , only_slice = True )
14811495 new_columns = self .items [~ is_deleted ]
1496+ # TODO shallow copy index?
14821497 axes = [new_columns , self .axes [1 ]]
14831498 return type (self )(tuple (nbs ), axes , verify_integrity = False )
14841499
@@ -1516,6 +1531,7 @@ def grouped_reduce(self, func: Callable) -> Self:
15161531 nrows = result_blocks [0 ].values .shape [- 1 ]
15171532 index = Index (range (nrows ))
15181533
1534+ # TODO shallow copy columns?
15191535 return type (self ).from_blocks (result_blocks , [self .axes [0 ], index ])
15201536
15211537 def reduce (self , func : Callable ) -> Self :
@@ -1539,6 +1555,7 @@ def reduce(self, func: Callable) -> Self:
15391555 res_blocks .extend (nbs )
15401556
15411557 index = Index ([None ]) # placeholder
1558+ # TODO shallow copy self.items
15421559 new_mgr = type (self ).from_blocks (res_blocks , [self .items , index ])
15431560 return new_mgr
15441561
@@ -1585,6 +1602,7 @@ def quantile(
15851602 assert is_list_like (qs ) # caller is responsible for this
15861603 assert axis == 1 # only ever called this way
15871604
1605+ # TODO shallow copy axes
15881606 new_axes = list (self .axes )
15891607 new_axes [1 ] = Index (qs , dtype = np .float64 )
15901608
@@ -1873,6 +1891,7 @@ def concat_horizontal(cls, mgrs: list[Self], axes: list[Index]) -> Self:
18731891
18741892 offset += len (mgr .items )
18751893
1894+ # TODO relevant axis already shallow-copied at caller?
18761895 new_mgr = cls (tuple (blocks ), axes )
18771896 return new_mgr
18781897
@@ -1942,6 +1961,7 @@ def to_2d_mgr(self, columns: Index) -> BlockManager:
19421961 arr = ensure_block_shape (blk .values , ndim = 2 )
19431962 bp = BlockPlacement (0 )
19441963 new_blk = type (blk )(arr , placement = bp , ndim = 2 , refs = blk .refs )
1964+ # TODO shallow copy index
19451965 axes = [columns , self .axes [0 ]]
19461966 return BlockManager ([new_blk ], axes = axes , verify_integrity = False )
19471967
0 commit comments