wesm/pandas — Issue #238: Joining with empty DataFrame on outer breaks
Author: creeson
Created: 2011-10-14 22:28:24+00:00
State: open

In some problems it is convenient to create an empty dataframe, and then append to it in a loop. The following code now breaks:

import pandas as ps
x = ps.DataFrame()
x.join(ps.DataFrame([3], index=[0], columns=['A']), how='outer')
x.join(ps.DataFrame([3], index=[0], columns=['A']))

Pandas 0.4.1

>>> import pandas as ps
>>> x = ps.DataFrame()
>>> x.join(ps.DataFrame([3], index=[0], columns=['A']), how='outer')
A
0 3

>>> x.join(ps.DataFrame([3], index=[0], columns=['A']))
Empty DataFrame
Index([], dtype=object)

Pandas 0.4.3

>>> import pandas as ps
>>> x = ps.DataFrame()
>>> x.join(ps.DataFrame([3], index=[0], columns=['A']), how='outer')

Traceback (most recent call last):
File "", line 1, in
x.join(ps.DataFrame([3], index=[0], columns=['A']), how='outer')
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2168, in join
return self._join_index(other, how, lsuffix, rsuffix)
File "C:\Python27\lib\site-packages\pandas\core\frame.py", line 2193, in _join_index
merged_data = join_managers(thisdata, otherdata, axis=1, how=how)
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 958, in join_managers
lblocks = _maybe_upcast_blocks(left.blocks, lneed_masking)
File "C:\Python27\lib\site-packages\pandas\core\internals.py", line 1029, in _maybe_upcast_blocks
return _consolidate(new_blocks, newb.ref_items)
UnboundLocalError: local variable 'newb' referenced before assignment

>>> x.join(ps.DataFrame([3], index=[0], columns=['A']))
Empty DataFrame
Index([], dtype=object)