Skip to content

Commit

Permalink
Merge pull request #2127 from ericpien/fix_growth_estimate
Browse files Browse the repository at this point in the history
Fix growth_estimates for new key `LTG`
  • Loading branch information
ValueRaider authored Nov 16, 2024
2 parents c535c44 + 0a3f9c7 commit 9f517a7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion tests/test_ticker.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ def test_growth_estimates(self):
columns = ['stock', 'industry', 'sector', 'index']
self.assertEqual(data.columns.values.tolist(), columns, "data has wrong column names")

index = ['0q', '+1q', '0y', '+1y', '+5y', '-5y']
index = ['0q', '+1q', '0y', '+1y']
self.assertEqual(data.index.values.tolist(), index, "data has wrong row names")

data_cached = self.ticker.growth_estimates
Expand Down
21 changes: 15 additions & 6 deletions yfinance/scrapers/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,18 @@ def growth_estimates(self) -> pd.DataFrame:
self._growth_estimates = pd.DataFrame()
return self._growth_estimates

# LTG is not defined in yahoo finance front-end as at 2024-11-14.
# But its addition is breaking the retrieval of growth estimates.
# Also, support for 5 year seem to have dropped.
# TODO: Revisit this change and consider permanently removing these keys.
data_dict = {
'0q': [],
'+1q': [],
'0y': [],
'+1y': [],
'+5y': [],
'-5y': []
# 'LTG': [],
# '+5y': [],
# '-5y': []
}

# make sure no column is empty
Expand All @@ -222,19 +227,23 @@ def growth_estimates(self) -> pd.DataFrame:

for item in self._earnings_trend:
period = item['period']
data_dict[period].append(item.get('growth', {}).get('raw', None))
if period in data_dict:
data_dict[period].append(item.get('growth', {}).get('raw', None))

for item in industry_trend:
period = item['period']
data_dict[period].append(item.get('growth', None))
if period in data_dict:
data_dict[period].append(item.get('growth', None))

for item in sector_trend:
period = item['period']
data_dict[period].append(item.get('growth', None))
if period in data_dict:
data_dict[period].append(item.get('growth', None))

for item in index_trend:
period = item['period']
data_dict[period].append(item.get('growth', None))
if period in data_dict:
data_dict[period].append(item.get('growth', None))

cols = ['stock', 'industry', 'sector', 'index']
self._growth_estimates = pd.DataFrame(data_dict, index=cols).T
Expand Down

0 comments on commit 9f517a7

Please sign in to comment.