Skip to content

Commit

Permalink
Merge pull request #8853 from behzadnouri/blk-mgr
Browse files Browse the repository at this point in the history
BUG: type change breaks BlockManager integrity
  • Loading branch information
jreback committed Nov 20, 2014
2 parents f010229 + 6809885 commit 5470f5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.15.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ Bug Fixes
- ``Timedelta`` kwargs may now be numpy ints and floats (:issue:`8757`).
- ``sql_schema`` now generates dialect appropriate ``CREATE TABLE`` statements (:issue:`8697`)
- ``slice`` string method now takes step into account (:issue:`8754`)
- Bug in ``BlockManager`` where setting values with different type would break block integrity (:issue:`8850`)
- Fix negative step support for label-based slices (:issue:`8753`)

Old behavior:
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2985,7 +2985,7 @@ def value_getitem(placement):
loc = [loc]

blknos = self._blknos[loc]
blklocs = self._blklocs[loc]
blklocs = self._blklocs[loc].copy()

unfit_mgr_locs = []
unfit_val_locs = []
Expand Down
11 changes: 11 additions & 0 deletions pandas/tests/test_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,17 @@ def test_set_change_dtype(self):
mgr2.set('quux', randn(N))
self.assertEqual(mgr2.get('quux').dtype, np.float_)

def test_set_change_dtype_slice(self): # GH8850
cols = MultiIndex.from_tuples([('1st','a'), ('2nd','b'), ('3rd','c')])
df = DataFrame([[1.0, 2, 3], [4.0, 5, 6]], columns=cols)
df['2nd'] = df['2nd'] * 2.0

self.assertEqual(sorted(df.blocks.keys()), ['float64', 'int64'])
assert_frame_equal(df.blocks['float64'],
DataFrame([[1.0, 4.0], [4.0, 10.0]], columns=cols[:2]))
assert_frame_equal(df.blocks['int64'],
DataFrame([[3], [6]], columns=cols[2:]))

def test_copy(self):
shallow = self.mgr.copy(deep=False)

Expand Down

0 comments on commit 5470f5c

Please sign in to comment.