Skip to content

Commit b2a1428

Browse files
clean-up fast_xs workarounds now it returns a SingleBlockManager
1 parent 81f6eae commit b2a1428

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

pandas/core/frame.py

-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
overload,
3131
)
3232
import warnings
33-
import weakref
3433

3534
import numpy as np
3635
import numpy.ma as ma
@@ -3493,10 +3492,6 @@ def _ixs(self, i: int, axis: int = 0):
34933492
self
34943493
)
34953494
result._set_is_copy(self, copy=copy)
3496-
# TODO(CoW) cleaner solution (eg let fast_xs return a SingleBM?)
3497-
if not copy and isinstance(self._mgr, BlockManager):
3498-
# assert len(self._mgr.blocks) == 1
3499-
result._mgr.refs = [weakref.ref(self._mgr.blocks[0])]
35003495
return result
35013496

35023497
# icol

pandas/core/generic.py

-5
Original file line numberDiff line numberDiff line change
@@ -3820,11 +3820,6 @@ class animal locomotion
38203820
result = self._constructor_sliced(
38213821
new_mgr, name=self.index[loc]
38223822
).__finalize__(self)
3823-
# TODO(CoW) cleaner solution (eg let fast_xs return a SingleBM?)
3824-
if isinstance(self._mgr, BlockManager) and len(self._mgr.blocks) == 1:
3825-
# in the case of a single block, new_values is a view
3826-
result._mgr.refs = [weakref.ref(self._mgr.blocks[0])]
3827-
38283823
elif is_scalar(loc):
38293824
result = self.iloc[:, slice(loc, loc + 1)]
38303825
elif axis == 1:

pandas/core/internals/managers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,9 @@ def fast_xs(self, loc: int) -> SingleBlockManager:
10651065
if len(self.blocks) == 1:
10661066
result = self.blocks[0].iget((slice(None), loc))
10671067
block = new_block(result, placement=slice(0, len(result)), ndim=1)
1068-
return SingleBlockManager(block, self.axes[0])
1068+
# in the case of a single block, the new block is a view
1069+
ref = weakref.ref(self.blocks[0])
1070+
return SingleBlockManager(block, self.axes[0], [ref])
10691071

10701072
dtype = interleaved_dtype([blk.dtype for blk in self.blocks])
10711073

0 commit comments

Comments
 (0)