ranaroussi / yfinance

Download market data from Yahoo! Finance's API
https://aroussi.com/post/python-yahoo-finance
Apache License 2.0
13.14k stars 2.33k forks source link

Code seems faulty #1305

Closed paulmcq closed 6 months ago

paulmcq commented 1 year ago

I have not seen a bug in execution, but reading this code in ranaroussi/yfinance/feature/prune-info/yfinance/scrapers/quote.py, it appears wrong to me.

I do not understand where this k gets a value in _scrape_complementary() line 293: if k not in key_stats:

ranaroussi/yfinance/feature/prune-info/yfinance/scrapers/quote.py: 290 .. 299

            json_data = json.loads(json_str)
            key_stats = json_data["timeseries"]["result"][0]
            if k not in key_stats:
                # Yahoo website prints N/A, indicates Yahoo lacks necessary data to calculate
                v = None
            else:
                # Select most recent (last) raw value in list:
                v = key_stats[k][-1]["reportedValue"]["raw"]
            self._info[k] = v
ValueRaider commented 1 year ago

Should be in a for k in keys: . Do you mind submitting a fix?

paulmcq commented 1 year ago

I would not mind submitting a fix, but I am not now set up to do development on yfinance. I know it is basically a git clone, then edit the file, push, and test. However, my code files and virtual environments are such a mess that it will take a while before that can be sanitary. I just noticed this whilst browsing the code. I do not even have a test case. I will eventually get straightened out, but thought it best to expose the issue sooner.