Skip to content

Commit

Permalink
CLN/BUG: Fix test errors in IEX
Browse files Browse the repository at this point in the history
Fix test errors in IEX
Mark API as unstable
  • Loading branch information
bashtage committed Jan 18, 2018
1 parent 011627c commit bf4e602
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
4 changes: 4 additions & 0 deletions pandas_datareader/exceptions.py
@@ -0,0 +1,4 @@
"""Custom warnings and exceptions"""

class UnstableAPIWarning(Warning):
pass
4 changes: 4 additions & 0 deletions pandas_datareader/iex/__init__.py
Expand Up @@ -39,6 +39,10 @@ def url(self):

def read(self):
df = super(IEX, self).read()
if isinstance(df, pd.DataFrame):
df = df.squeeze()
if not isinstance(df, pd.DataFrame):
df = pd.DataFrame(df)
return df

def _get_params(self, symbols):
Expand Down
5 changes: 5 additions & 0 deletions pandas_datareader/iex/deep.py
Expand Up @@ -11,6 +11,11 @@
class Deep(IEX):
def __init__(self, symbols=None, service=None, start=None, end=None,
retry_count=3, pause=0.001, session=None):
if isinstance(symbols, str):
symbols = symbols.lower()
else:
symbols = [s.lower() for s in symbols]

super(Deep, self).__init__(symbols=symbols,
start=start, end=end,
retry_count=retry_count,
Expand Down
9 changes: 8 additions & 1 deletion pandas_datareader/iex/stats.py
@@ -1,7 +1,11 @@
import pandas as pd
from datetime import datetime, timedelta

import pandas as pd

from pandas_datareader.exceptions import UnstableAPIWarning
from pandas_datareader.iex import IEX


# Data provided for free by IEX
# Data is furnished in compliance with the guidelines promulgated in the IEX
# API terms of service and manual
Expand All @@ -12,6 +16,9 @@
class DailySummaryReader(IEX):
def __init__(self, symbols=None, start=None, end=None, retry_count=3,
pause=0.001, session=None):
import warnings
warnings.warn('Daily statistics is not working due to issues with the IEX API',
UnstableAPIWarning)
self.curr_date = start
super(DailySummaryReader, self).__init__(symbols=symbols,
start=start, end=end,
Expand Down
15 changes: 7 additions & 8 deletions pandas_datareader/tests/test_iex.py
@@ -1,9 +1,8 @@
import pytest

import pandas.util.testing as tm
from datetime import datetime, timedelta

import pytest
from pandas import DataFrame
from datetime import datetime, timedelta

from pandas_datareader.data import (DataReader, get_summary_iex, get_last_iex,
get_dailysummary_iex, get_iex_symbols,
get_iex_book)
Expand All @@ -25,8 +24,9 @@ def test_historical(self):

def test_false_ticker(self):
df = get_last_iex("INVALID TICKER")
tm.assert_frame_equal(df, DataFrame())
assert df.shape[0] == 0

@pytest.mark.xfail(reason='IEX daily history API is returning 500 as of Jan 2018')
def test_daily(self):
df = get_dailysummary_iex(start=datetime(2017, 5, 5),
end=datetime(2017, 5, 6))
Expand All @@ -43,6 +43,5 @@ def test_live_prices(self):
assert df["price"].mean() > 0

def test_deep(self):
dob = get_iex_book('GS', service='system-event')
assert len(dob['eventResponse']) > 0
assert dob['timestamp'] > datetime.now() - timedelta(days=1)
dob = get_iex_book('GS', service='book')
assert 'GS' in dob

0 comments on commit bf4e602

Please sign in to comment.