question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnboundLocalError: local variable 'df' referenced before assignment

See original GitHub issue

Which 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
enoch-princecommented, Sep 4, 2021

@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!

0reactions
twopirllccommented, Sep 4, 2021

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found