-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
UnboundLocalError: local variable 'boxprops' referenced before assignment #3647
Comments
Please provide a reproducible example, thank! |
There is a for loop in the routine in categorical.py. The variable boxprops is set for various cases inside the for loop. It is undefined before the loop and used afterwards. It just doesn't imagine the case where there is no data and the for loop has 0 iterations. Setting boxprops = None before the start of the loop cures the problem. |
A reproducible example is code that can be copy-pasted in toto to demonstrate the problem. Thanks! |
It is hard to reproduce the exact context. If you add |
I don’t understand why it is so hard to just show the actual code you are using. Even if your suggested change is correct, we will still want to add a test for the edge case, and that requires understanding the circumstances where it arises. |
@catskillsresearch: The external file you link to has too many dependencies to try to run it here. And even then, we don't know which input has been used. It would help if you'd inspect the values and datatypes of @mwaskom: Trying to reproduce, I can only see the crash with sns.boxplot(data=[None, None], palette=['r', 'b']) This gives a warning:
Doing the same without sns.boxplot(data=[None, None])
Replacing Maybe, instead of adding an extra |
Thanks for looking into it @jhncls! It would also be very helpful to know what is |
Testing with different guesses for Testing with other functions, it seems only By the way, A limited list of extravagant inputs that crash (and only with
|
Not sure if exactly the same, but I ran into this issue while trying to adhere to the import numpy as np, pandas as pd, seaborn as sns
cat_color = ['Black', 'Brown', 'Orange']
mu, sigma = [1.0, 2.5, 4.0], [0.5, 0.75, 0.5]
cat_silliness = np.random.normal(mu, sigma, (100, 3))
df = pd.DataFrame(columns=cat_color, data=cat_silliness)
melted = df.melt(var_name='CatColor', value_name='Silliness')
sns.boxplot(x='CatColor', y='Silliness',
data=melted, showfliers=False, palette='tab10',
order=cat_color[::-1], legend=False)
Simply replacing
This is technically a user error since I failed to replace |
I was stuck with this error for a long time but I am not sure if it is the same cause. In essence, this error popped up when listing an invalid order. See https://github.com/MischaelR/seaborn_unboundlocalerror/blob/main/test_facetgrid.py For this particular example, I think a more descriptive error message would be beneficial. |
Hi there, I can't seem to run this function:
Im getting an error:
Ive tried to use GPT4 to help resolve it and tried many things but it's not working. Could you please advise what to do? |
Hi Ekaterina, |
I am confused as to why you say my post is unrelated to this thread. The thread title and my error are exactly the same: "UnboundLocalError: local variable 'boxprops' referenced before assignment". The % issue you are referring to is a warning not an error. If you add boxprops = None on line 630 of categorical.py, the problem I experienced will not recur as per above comment, however it still doesn't plot anything. I am expecting plots as per this post: https://www.kaggle.com/code/learnmore1/deep-reinforcement-learning-for-stock-trading-1/notebook. Could you help? The data I have are attached here. |
If you take a look at your stack trace, you should see that the (initial) call that caused the problem was in However, if you look right above your first comment here, you will see a mention of this issue in a pyfolio pull request (stefan-jansen/pyfolio-reloaded#47). That pull request addresses your exact problem, so updating your pyfolio to version 0.9.7 might help. |
On Python 3.9.7, with a fresh pip install seaborn, at line 1373 of this function, with this call:
I get this error:
The text was updated successfully, but these errors were encountered: