diff --git a/doc/source/release.rst b/doc/source/release.rst index c42c9920efef1..434477d071c4b 100644 --- a/doc/source/release.rst +++ b/doc/source/release.rst @@ -228,7 +228,7 @@ Bug Fixes - Bug in ``.xs`` with a ``nan`` in level when dropped (:issue:`6574`) - Bug in fillna with method = 'bfill/ffill' and ``datetime64[ns]`` dtype (:issue:`6587`) - Bug in sql writing with mixed dtypes possibly leading to data loss (:issue:`6509`) - +- Bug in popping from a Series (:issue:`6600`) pandas 0.13.1 ------------- diff --git a/pandas/core/internals.py b/pandas/core/internals.py index 2a4ee4dcf8cf6..a5b9e874cea41 100644 --- a/pandas/core/internals.py +++ b/pandas/core/internals.py @@ -3733,11 +3733,21 @@ def reindex_axis0_with_method(self, new_axis, indexer=None, method=None, def _delete_from_block(self, i, item): super(SingleBlockManager, self)._delete_from_block(i, item) - # reset our state - self._block = ( - self.blocks[0] if len(self.blocks) else - make_block(np.array([], dtype=self._block.dtype), [], []) - ) + # possibly need to merge split blocks + if len(self.blocks) > 1: + new_items = Index(list(itertools.chain(*[ b.items for b in self.blocks ]))) + block = make_block(np.concatenate([ b.values for b in self.blocks ]), + new_items, + new_items, + dtype=self._block.dtype) + + elif len(self.blocks): + block = self.blocks[0] + else: + block = make_block(np.array([], dtype=self._block.dtype), [], []) + + self.blocks = [block] + self._block = block self._values = self._block.values def get_slice(self, slobj): diff --git a/pandas/tests/test_series.py b/pandas/tests/test_series.py index ca1b23ee26da4..93fa739f7f218 100644 --- a/pandas/tests/test_series.py +++ b/pandas/tests/test_series.py @@ -710,6 +710,21 @@ def test_setindex(self): def test_array_finalize(self): pass + def test_pop(self): + # GH 6600 + df = DataFrame({ + 'A': 0, + 'B': np.arange(5,dtype='int64'), + 'C': 0, + }) + k = df.iloc[4] + + result = k.pop('B') + self.assertEqual(result, 4) + + expected = Series([0,0],index=['A','C']) + assert_series_equal(k, expected) + def test_not_hashable(self): s_empty = Series() s = Series([1])