Skip to content

Commit a71ede3

Browse files
committed
Merge pull request #6601 from jreback/pop
BUG: Bug in popping from a Series (GH6600)
2 parents b94c576 + 0a0e3b3 commit a71ede3

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

doc/source/release.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Bug Fixes
228228
- Bug in ``.xs`` with a ``nan`` in level when dropped (:issue:`6574`)
229229
- Bug in fillna with method = 'bfill/ffill' and ``datetime64[ns]`` dtype (:issue:`6587`)
230230
- Bug in sql writing with mixed dtypes possibly leading to data loss (:issue:`6509`)
231-
231+
- Bug in popping from a Series (:issue:`6600`)
232232

233233
pandas 0.13.1
234234
-------------

pandas/core/internals.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -3733,11 +3733,21 @@ def reindex_axis0_with_method(self, new_axis, indexer=None, method=None,
37333733
def _delete_from_block(self, i, item):
37343734
super(SingleBlockManager, self)._delete_from_block(i, item)
37353735

3736-
# reset our state
3737-
self._block = (
3738-
self.blocks[0] if len(self.blocks) else
3739-
make_block(np.array([], dtype=self._block.dtype), [], [])
3740-
)
3736+
# possibly need to merge split blocks
3737+
if len(self.blocks) > 1:
3738+
new_items = Index(list(itertools.chain(*[ b.items for b in self.blocks ])))
3739+
block = make_block(np.concatenate([ b.values for b in self.blocks ]),
3740+
new_items,
3741+
new_items,
3742+
dtype=self._block.dtype)
3743+
3744+
elif len(self.blocks):
3745+
block = self.blocks[0]
3746+
else:
3747+
block = make_block(np.array([], dtype=self._block.dtype), [], [])
3748+
3749+
self.blocks = [block]
3750+
self._block = block
37413751
self._values = self._block.values
37423752

37433753
def get_slice(self, slobj):

pandas/tests/test_series.py

+15
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,21 @@ def test_setindex(self):
710710
def test_array_finalize(self):
711711
pass
712712

713+
def test_pop(self):
714+
# GH 6600
715+
df = DataFrame({
716+
'A': 0,
717+
'B': np.arange(5,dtype='int64'),
718+
'C': 0,
719+
})
720+
k = df.iloc[4]
721+
722+
result = k.pop('B')
723+
self.assertEqual(result, 4)
724+
725+
expected = Series([0,0],index=['A','C'])
726+
assert_series_equal(k, expected)
727+
713728
def test_not_hashable(self):
714729
s_empty = Series()
715730
s = Series([1])

0 commit comments

Comments
 (0)