Skip to content

Commit

Permalink
Merge pull request #1342 from ranaroussi/hotfix/basic_info
Browse files Browse the repository at this point in the history
Fix 'Ticker.basic_info' lazy-loading
  • Loading branch information
ValueRaider committed Jan 25, 2023
2 parents 8e5c94a + ba8621f commit b5badbb
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions yfinance/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,17 @@ def __init__(self, tickerBaseObject):

# dict imitation:
def keys(self):
attrs = utils.attributes(self)
return attrs.keys()
# attrs = utils.attributes(self)
# return attrs.keys()
# utils.attributes is calling each method, bad!
# Have to hardcode
keys = ["currency", "exchange", "timezone"]
keys += ["shares", "market_cap"]
keys += ["last_price", "previous_close", "open", "day_high", "day_low"]
keys += ["last_volume"]
keys += ["fifty_day_average", "two_hundred_day_average", "ten_day_average_volume", "three_month_average_volume"]
keys += ["year_high", "year_low", "year_change"]
return keys
def items(self):
return [(k,self[k]) for k in self.keys()]
def __getitem__(self, k):
Expand Down Expand Up @@ -198,7 +207,7 @@ def shares(self):
# Requesting 18 months failed, so fallback to shares which should include last year
shares = self._tkr.get_shares()
if shares is None:
raise Exception(f"{self._tkr.ticker}: Cannot retrieve share count for calculating market cap")
raise Exception(f"{self._tkr.ticker}: Cannot retrieve share count")
if isinstance(shares, pd.DataFrame):
shares = shares[shares.columns[0]]
self._shares = shares.iloc[-1]
Expand Down

0 comments on commit b5badbb

Please sign in to comment.