UnboundLocalError: local variable 'df' referenced before assignment
See original GitHub issueWhich version are you running? The lastest version is on Github. Pip is for major releases.
import pandas_ta as ta
print(ta.version)
I'm running version 0.3.14b0
Description of the bug I keep getting an UnboundedLocalError saying local variable ‘df’ referenced before assignment. The piece of code is below:
To Reproduce
import pandas as pd
import pandas_ta as ta
df = pd.DataFrame()
tesla = df.ta.ticker('tsla', period='3mo')
Expected behavior I expected to get a dataframe object with a 3 month historical data for the Tesla stock
Full Traceback
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\MKEDONKOR\.virtualenvs\Stock-Patterns-tBWpuVT_\lib\site-packages\pandas_ta\core.py", line
851, in ticker
df = yf(ticker, **kwargs)
File "C:\Users\MKEDONKOR\.virtualenvs\Stock-Patterns-tBWpuVT_\lib\site-packages\pandas_ta\utils\data\yahoofinance.py", line 99, in yf
if df.empty: return
UnboundLocalError: local variable 'df' referenced before assignment
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Python 3: UnboundLocalError: local variable referenced ...
This local variable masks the global variable. ... in main print f(3) UnboundLocalError: local variable 'f' referenced before assignment.
Read more >Python local variable referenced before assignment Solution
The UnboundLocalError: local variable referenced before assignment error is raised when you try to assign a value to a local variable before it ......
Read more >UnboundLocalError: local variable referenced before ...
In Python, variables that are only referenced inside a function are implicitly global. If a variable is assigned a value anywhere within the ......
Read more >Local Variable Referenced Before Assignment - STechies
The “local variable referenced before assignment” error occurs when you give reference of a local variable without assigning any value. Example:
Read more >Local variable referenced before assignment in Python
The Python "UnboundLocalError: Local variable referenced before assignment" occurs when we reference a local variable before assigning a value to it in a ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@twopirllc
I restarted VS Code and tried to reproduce the bug without the line of code you suggested and it worked. I tried it again and it still worked. It’s kind of strange.
I have added the line of code now and it still works.
Cheers!
@enoch-prince,
Awesome! I appreciate you responding promptly and the temporary fix solves the
UnboundLocalError
issue. I will add the fix for the next version so it does not occur again.Thank you, KJ