Skip to content

Commit 5abb534

Browse files
committed
BUG: join should not fail on unconsolidated DataFrame objects, GH #331
1 parent 322cedd commit 5abb534

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pandas/core/internals.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -989,14 +989,16 @@ class _JoinOperation(object):
989989
BlockManager data structures
990990
"""
991991
def __init__(self, left, right, axis=1, how='left'):
992+
if not left.is_consolidated():
993+
left = left.consolidate()
994+
if not right.is_consolidated():
995+
right = right.consolidate()
996+
992997
self.left = left
993998
self.right = right
994999
self.axis = axis
9951000
self.how = how
9961001

997-
assert(left.is_consolidated())
998-
assert(right.is_consolidated())
999-
10001002
laxis = left.axes[axis]
10011003
raxis = right.axes[axis]
10021004

pandas/tests/test_frame.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3378,6 +3378,15 @@ def test_join_empty_bug(self):
33783378
x = DataFrame()
33793379
x.join(DataFrame([3], index=[0], columns=['A']), how='outer')
33803380

3381+
def test_join_unconsolidated(self):
3382+
# GH #331
3383+
a = DataFrame(randn(30,2), columns=['a','b'])
3384+
c = Series(randn(30))
3385+
a['c'] = c
3386+
d = DataFrame(randn(30,1), columns=['d'])
3387+
3388+
a.join(d)
3389+
33813390
def _join_by_hand(a, b, how='left'):
33823391
join_index = a.index.join(b.index, how=how)
33833392

0 commit comments

Comments
 (0)