Skip to content

Commit 97a5d1e

Browse files
jrebackgouthambs
authored andcommitted
BUG: Bug in popping from a Series (GH6600)
1 parent 57db1c2 commit 97a5d1e

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
@@ -226,7 +226,7 @@ Bug Fixes
226226
- Bug in ``.xs`` with a ``nan`` in level when dropped (:issue:`6574`)
227227
- Bug in fillna with method = 'bfill/ffill' and ``datetime64[ns]`` dtype (:issue:`6587`)
228228
- Bug in sql writing with mixed dtypes possibly leading to data loss (:issue:`6509`)
229-
229+
- Bug in popping from a Series (:issue:`6600`)
230230

231231
pandas 0.13.1
232232
-------------

pandas/core/internals.py

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

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

37413751
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)