dgunning / edgartools

Navigate SEC Edgar data in Python
MIT License
411 stars 83 forks source link

{'error': "An error occurred: 'functools._lru_cache_wrapper' object has no attribute 'ticker'"} #69

Closed marwinsteiner closed 1 month ago

marwinsteiner commented 2 months ago

Trying to look up some financial statement info for a specific ticker but getting a bit confused...

I have this function:

def handle_financial_info_request(ticker: str, statement_type: str, year: Optional[int] = None) -> Dict[str, Any]:
    try:
        company = Company.ticker(ticker)

        if statement_type == "balance_sheet":
            financial_data = company.xbrl().balance_sheet
        elif statement_type == "cash_flow":
            financial_data = company.xbrl().cash_flow
        elif statement_type == "income_statement":
            financial_data = company.xbrl().income_statement
        else:
            return {"error": f"Invalid statement type: {statement_type}"}

        df = pd.DataFrame(financial_data)
        df = df.set_index('Unnamed: 0')

        if not year:
            return df.to_dict()

        if str(year) in df.columns:
            return df[str(year)].to_dict()
        else:
            return {"error": f"Data for year {year} not available"}
    except Exception as e:
        return {"error": f"An error occurred: {str(e)}"}

But for the error I get 'functools._lru_cache_wrapper' object has no attribute 'ticker' Halp! What to do?

dgunning commented 2 months ago

Try

company = Company(ticker)
marwinsteiner commented 1 month ago

I have to apologize for this... Yep, you're right -- shortly after opening the issue, I tried that and it worked and forgot about the open issue. Sorry about that, my mistake! On another note the library is pretty powerful, I have to say. I know that there's a lot going on under the hood -- impressive how easy the library is to use if you use your brain, like I didn't^^. ;-)