Skip to content

UnboundLocalError in _concat_single_item() #3833

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

Closed
stefan-pmc opened this issue Jun 10, 2013 · 15 comments · Fixed by #3864
Closed

UnboundLocalError in _concat_single_item() #3833

stefan-pmc opened this issue Jun 10, 2013 · 15 comments · Fixed by #3864
Labels
Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@stefan-pmc
Copy link

The exception handling code in _get_concatenated_data() relies on the exception not being generated in self._prepare_blocks() and can generate an exception with this non-informative error message:

Traceback (most recent call last):
  File "<pyshell#5>", line 12, in <module>
    df = pd.concat([activedf,closeddf])
  File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 873, in concat
    return op.get_result()
  File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 957, in get_result
    new_data = self._get_concatenated_data()
  File "C:\Python27\lib\site-packages\pandas\tools\merge.py", line 1001, in _get_concatenated_data
    new_data[item] = self._concat_single_item(rdata, item)
UnboundLocalError: local variable 'rdata' referenced before assignment
@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

though I fixed this....just need to move the first statement outside of the try: except: PR?

@stefan-pmc
Copy link
Author

yes, thanks; just wanted to report. sorry didn't find any previous report.

@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

oh....it still looks like an error, what I meant was do you want to submit a PR to fix?

@jreback jreback reopened this Jun 10, 2013
@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

@stefan-pmc do you have a case that reproduces this?

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

@stefan-pmc if u provide the case i will fix :)

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

unless u want to submit a PR that is great too!

@stefan-pmc
Copy link
Author

hard to supply the actual data but basically the error will happen for example if you try to do pd.concat() on a bunch of dataframes where one of them has an index with duplicates in it. if you move the first line outside the try block then it will generate the correct error message (cannot reindex with non unique index values), so that should do the job.
can submit a PR if that is of additional use and if you tell me what a PR is.

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

oh sorry :) a PR == pull request...do u need additional details about pull requests? happy to oblige!

@stefan-pmc
Copy link
Author

yes please explain – though it sounds like a very weighty approach for such a small bug.

@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

no...the reason for the PR is that you can test locally, make sure everything passes, then travis tests it (the continuous integration service) to make sure it is passing on many different configurations

seemingly trivial issues can cause issues later if they break things (or worse, DONT break things which we don't have a test for)

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

I always assume the worst with unbound local errors since there are subtle issues surrounding scope, binding, and exceptions in Python across versions.

@stefan-pmc
Copy link
Author

yes, that makes sense, though in this case I think it is simply that it creates the variable rdata inside the try block and then uses it in the exception handler part; what happened is that an exception is generated before the variable is created. taking the first line out of the try block solves that problem. not sure if that itself creates problems elsewhere of course.

@cpcloud
Copy link
Member

cpcloud commented Jun 10, 2013

try running nosetests -w pandas in the pandas directory...that'll tell u if something u did broke things

@jreback
Copy link
Contributor

jreback commented Jun 10, 2013

@stefan-pmc they may be exactly the case, the problem is changing it without having a test case is not good because the next change may break this one :)

@jreback
Copy link
Contributor

jreback commented Jun 12, 2013

thanks......I cannot reproduce the error unless I actually have a code-error in the prepare_blocks itself....so just fixing the code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants