Skip to content

Commit

Permalink
Repaired earnings and financials for certain symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
Addison Lynch authored and Addison Lynch committed May 24, 2018
1 parent c723397 commit 4912720
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions docs/source/whatsnew/v0.3.4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _whatsnew_034:


v0.3.4 (TBA)
-----------------------

This is a minor release from 0.3.4.

Bug Fixes
~~~~~~~~~

- Fix KeyError exception when there is no earnings or financials data on a ticker. (Thank you reixd)
`GH60 <https://github.com/addisonlynch/iexfinance/pull/60>`__
4 changes: 2 additions & 2 deletions iexfinance/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def get_earnings(self, **kwargs):
Stocks Earnings endpoint data
"""
data = self._get_endpoint("earnings", kwargs)
return {symbol: data[symbol]["earnings"]["earnings"]
return {symbol: data[symbol]["earnings"].get("earnings", [])
for symbol in list(data)}

@output_format(override=None)
Expand Down Expand Up @@ -387,7 +387,7 @@ def get_financials(self, **kwargs):
Stocks Financials endpoint data
"""
data = self._get_endpoint("financials", kwargs)
return {symbol: data[symbol]["financials"]["financials"]
return {symbol: data[symbol]["financials"].get("financials", [])
for symbol in list(data)}

@output_format(override=None)
Expand Down
9 changes: 9 additions & 0 deletions tests/test_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def setup_class(self):
self.cshare4 = Stock("aapl",
json_parse_int=Decimal,
json_parse_float=Decimal)
self.cshare5 = Stock("gig^")

def test_invalid_symbol(self):
data = Stock("BAD SYMBOL")
Expand Down Expand Up @@ -135,6 +136,10 @@ def test_get_earnings_format(self):
data2 = self.cshare2.get_earnings()
assert isinstance(data2, pd.DataFrame)

# Ensure empty list is returned for symbol with no earnings
data3 = self.cshare5.get_earnings()
assert isinstance(data3, list)

def test_get_effective_spread_format(self):
data = self.cshare.get_effective_spread()
assert isinstance(data, list)
Expand All @@ -149,6 +154,10 @@ def test_get_financials_format(self):
data2 = self.cshare2.get_financials()
assert isinstance(data2, pd.DataFrame)

# Ensure empty list is returned even when ticker has no financials
data3 = self.cshare5.get_financials()
assert isinstance(data3, list)

def test_get_key_stats_format(self):
data = self.cshare.get_key_stats()
assert isinstance(data, dict)
Expand Down

0 comments on commit 4912720

Please sign in to comment.