Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Joining with empty DataFrame on outer breaks #238

Closed
creeson opened this issue Oct 14, 2011 · 4 comments
Closed

Joining with empty DataFrame on outer breaks #238

creeson opened this issue Oct 14, 2011 · 4 comments
Labels
Milestone

Comments

@creeson
Copy link

creeson commented Oct 14, 2011

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 "<pyshell#1197>", 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)

@wesm
Copy link
Member

wesm commented Oct 15, 2011

Thanks for the bug report-- I'll get this fixed in the next release (happening pretty soon)

@wesm
Copy link
Member

wesm commented Oct 15, 2011

This appears to have been fixed during some refactoring I did to the code supporting the join method recently. I added a test per above to verify that this works.

@wesm wesm closed this as completed Oct 15, 2011
@creeson
Copy link
Author

creeson commented Oct 15, 2011

Thanks! Also, mildly related, are there any plans to allow the creation of an empty Panel? Or are there issues associated with this?

@wesm
Copy link
Member

wesm commented Oct 15, 2011

that should actually be possible. i'll see if I can fix that-- not sure what the downstream implications might be. will tag you in a separate GH issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants