Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair earnings and financials indexing #35

Merged
merged 2 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/source/whatsnew/v0.4.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.. _whatsnew_030:


v0.4.0 (TBA)
-------------------------

This is a major release from 0.3.0, and we recommend that all users
update.



- Some Stocks endpoints return incorrectly
`GH34 <https://github.com/addisonlynch/iexfinance/issues/34>`__
6 changes: 4 additions & 2 deletions iexfinance/stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def get_earnings(self, **kwargs):
Stocks Earnings endpoint data
"""
data = self._get_endpoint("earnings", kwargs)
return {symbol: data[symbol]["earnings"] for symbol in list(data)}
return {symbol: data[symbol]["earnings"]["earnings"]
for symbol in list(data)}

@output_format(override=None)
def get_effective_spread(self, **kwargs):
Expand All @@ -369,7 +370,8 @@ def get_financials(self, **kwargs):
Stocks Financials endpoint data
"""
data = self._get_endpoint("financials", kwargs)
return {symbol: data[symbol]["financials"] for symbol in list(data)}
return {symbol: data[symbol]["financials"]["financials"]
for symbol in list(data)}

@output_format(override=None)
def get_key_stats(self, **kwargs):
Expand Down
42 changes: 23 additions & 19 deletions tests/test_stock.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@

import sys

_SYS_VERSION_MAJOR = sys.version_info.major
PY3 = sys.version_info.major == 3

if PY3:
string_types = (str, )
else:
string_types = (str, unicode)


class TestBase(object):
Expand Down Expand Up @@ -125,7 +130,7 @@ def test_get_dividends_params(self):

def test_get_earnings_format(self):
data = self.cshare.get_earnings()
assert isinstance(data, dict)
assert isinstance(data, list)

data2 = self.cshare2.get_earnings()
assert isinstance(data2, pd.DataFrame)
Expand All @@ -139,7 +144,7 @@ def test_get_effective_spread_format(self):

def test_get_financials_format(self):
data = self.cshare.get_financials()
assert isinstance(data, dict)
assert isinstance(data, list)

data2 = self.cshare2.get_financials()
assert isinstance(data2, pd.DataFrame)
Expand Down Expand Up @@ -214,8 +219,9 @@ def test_get_quote_format(self):
def test_get_quote_params(self):
data = self.cshare.get_quote()
data2 = self.cshare.get_quote(displayPercent=True)
assert abs(data["ytdChange"]) < .1
assert abs(data2["ytdChange"]) > .1

assert (abs(data2["ytdChange"]) >
abs(data["ytdChange"]))

def test_get_relevant_format(self):
data = self.cshare.get_relevant()
Expand Down Expand Up @@ -248,6 +254,11 @@ def test_get_volume_by_venue_format(self):
data2 = self.cshare2.get_volume_by_venue()
assert isinstance(data2, pd.DataFrame)

def test_filter(self):
data = self.cshare.get_quote(filter_='ytdChange')
assert isinstance(data, dict)
assert isinstance(data["ytdChange"], float)


class TestBatchDefault(object):

Expand Down Expand Up @@ -427,8 +438,8 @@ def test_get_quote_format(self):
assert isinstance(data2, pd.DataFrame)

data3 = self.cbatch.get_quote(displayPercent=True)
assert abs(data["AAPL"]["ytdChange"]) < .1
assert abs(data3["AAPL"]["ytdChange"]) > .1
assert (abs(data3["AAPL"]["ytdChange"]) >
abs(data["AAPL"]["ytdChange"]))

def test_get_relevant_format(self):
data = self.cbatch.get_relevant()
Expand Down Expand Up @@ -478,32 +489,25 @@ def setup_class(self):
def test_get_company_name(self):
data = self.share.get_company_name()
print(type(data))
if _SYS_VERSION_MAJOR < 3:
assert isinstance(data, unicode)
else:
assert isinstance(data, str)

assert isinstance(data, string_types)
assert data == "Apple Inc."

data2 = self.share2.get_company_name()
assert isinstance(data2, pd.DataFrame)

def test_get_primary_exchange(self):
data = self.share.get_primary_exchange()
if _SYS_VERSION_MAJOR < 3:
assert isinstance(data, unicode)
else:
assert isinstance(data, str)
assert isinstance(data, string_types)
assert data == "Nasdaq Global Select"

data2 = self.share2.get_primary_exchange()
assert isinstance(data2, pd.DataFrame)

def test_get_sector(self):
data = self.share.get_sector()
if _SYS_VERSION_MAJOR < 3:
assert isinstance(data, unicode)
else:
assert isinstance(data, str)

assert isinstance(data, string_types)
assert data == "Technology"

data2 = self.share2.get_sector()
Expand Down